Opened 3 years ago

Closed 23 months ago

#12143 closed bug (fixed)

ApplicativeDo Fails to Desugar 'return True'

Reported by: MichaelBurge Owned by: simonmar
Priority: normal Milestone: 8.4.1
Component: Compiler Version: 8.0.1
Keywords: ApplicativeDo Cc: RyanGlScott, simonmar
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4128
Wiki Page:

Description (last modified by MichaelBurge)

ApplicativeDo correctly infers Functor if I bind an unused variable:

Prelude> :t \m -> do { x <- m; return True; }
\m -> do { x <- m; return True; } :: Functor f => f t -> f Bool

Prelude> :t \m -> do { m; return True; }
\m -> do { m; return True; } :: Monad m => m a -> m Bool

It seems like if 'x' is unused, then 'x <- m' and 'm' should be equivalent.

And maybe 'return True' should be Monad, but 'do { return True; }' should be Applicative?

Change History (9)

comment:1 Changed 3 years ago by MichaelBurge

Description: modified (diff)

comment:2 Changed 3 years ago by RyanGlScott

Cc: RyanGlScott added

comment:3 Changed 3 years ago by MichaelBurge

Description: modified (diff)

comment:4 Changed 3 years ago by thomie

Cc: simonmar added
Keywords: ApplicativeDo added

comment:5 Changed 3 years ago by simonmar

Blocked By: 10892 added
Milestone: 8.2.1
Owner: set to simonmar

I think this is really part of #10892. Currently ApplicativeDo does not handle guard statements (those without a <-) at all.

comment:6 Changed 3 years ago by bgamari

Milestone: 8.2.18.4.1

This won't happen for 8.2.

comment:7 Changed 2 years ago by simonmar

Differential Rev(s): Phab:D4128

comment:8 Changed 2 years ago by Simon Marlow <marlowsd@…>

In 41f9055/ghc:

ApplicativeDo: handle BodyStmt (#12143)

Summary:
It's simple to treat BodyStmt just like a BindStmt with a wildcard
pattern, which is enough to fix #12143 without going all the way to
using `<*` and `*>` (#10892).

Test Plan:
* new test cases in `ado004.hs`
* validate

Reviewers: niteria, simonpj, bgamari, austin, erikd

Subscribers: rwbarton, thomie

GHC Trac Issues: #12143

Differential Revision: https://phabricator.haskell.org/D4128

comment:9 Changed 23 months ago by simonmar

Blocked By: 10892 removed
Resolution: fixed
Status: newclosed

Probably shouldn't merge this into the stable branch because it changes inferred types.

Note: See TracTickets for help on using tickets.