Opened 4 years ago

Closed 4 years ago

#11607 closed bug (fixed)

ApplicativeDo easily foiled with `pure`

Reported by: bgamari Owned by: bgamari
Priority: high Milestone: 8.0.1
Component: Compiler (Type checker) Version: 8.0.1-rc2
Keywords: ApplicativeDo Cc: simonmar, ocharles
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case: ado/T11607
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D1931
Wiki Page:

Description

ApplicativeDo fails to desugar do blocks ending with pure. For instance,

{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

newtype MaybeA a = MaybeA (Maybe a)
                 deriving (Show, Functor, Applicative)

main = print $ do x <- MaybeA $ Just 42
                  pure x

However, if the final pure is changed to return things work as expected.

Change History (8)

comment:1 Changed 4 years ago by ocharles

Cc: ocharles added

comment:2 Changed 4 years ago by bgamari

Owner: set to bgamari

comment:3 Changed 4 years ago by bgamari

Differential Rev(s): Phab:D1931
Status: newpatch

comment:4 Changed 4 years ago by bgamari

Test Case: ado/T11607

comment:5 Changed 4 years ago by simonpj

Yikes! there is no user-manual documentation about the magical behaviour of return. Adding more magic (pure or return) sees uncool. E.g. if I have then using blah will surprisingly fail. Simon M?

Regardless whatever the behaviour is ought to be carefully specified in the user manual.

So I'm not complaining about Phab:D1931, but rather asking for proper documentation.

comment:6 Changed 4 years ago by Ben Gamari <ben@…>

In 0c7db61f/ghc:

ApplicativeDo: Handle terminal `pure` statements

ApplicativeDo handled terminal `return` statements properly, but not
`pure`.

Test Plan: Validate with included testcase

Reviewers: austin, simonmar

Reviewed By: austin, simonmar

Subscribers: simonpj, thomie

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

GHC Trac Issues: #11607

comment:7 Changed 4 years ago by bgamari

Status: patchmerge

comment:8 Changed 4 years ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.