Commit 0c7db61f authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

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
parent 8e19d3a3
......@@ -1678,7 +1678,7 @@ isReturnApp (L _ (HsApp f arg))
| otherwise = Nothing
where
is_return (L _ (HsPar e)) = is_return e
is_return (L _ (HsVar (L _ r))) = r == returnMName
is_return (L _ (HsVar (L _ r))) = r == returnMName || r == pureAName
-- TODO: I don't know how to get this right for rebindable syntax
is_return _ = False
isReturnApp _ = Nothing
......
......@@ -906,7 +906,8 @@ is as follows. If the do-expression has the following form: ::
where none of the variables defined by ``p1...pn`` are mentioned in ``E1...En``,
then the expression will only require ``Applicative``. Otherwise, the expression
will require ``Monad``.
will require ``Monad``. The block may return a pure expression ``E`` depending
upon the results ``p1...pn`` with either ``return`` or ``pure``.
.. _applicative-do-pitfall:
......
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
newtype MaybeA a = MaybeA (Maybe a)
deriving (Show, Functor, Applicative)
main :: IO ()
main = print $ do
x <- MaybeA $ Just 42
pure x
......@@ -5,3 +5,4 @@ test('ado004', normal, compile, [''])
test('ado005', normal, compile_fail, [''])
test('ado006', normal, compile, [''])
test('ado007', normal, compile, [''])
test('T11607', normal, compile_and_run, [''])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment