[commit: ghc] master: ApplicativeDo: Handle terminal `pure` statements (0c7db61)
git at git.haskell.org
git at git.haskell.org
Thu Feb 25 14:40:52 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/0c7db61f8a17b2c5c4335b62103eb9ffc5d24154/ghc
>---------------------------------------------------------------
commit 0c7db61f8a17b2c5c4335b62103eb9ffc5d24154
Author: Ben Gamari <bgamari.foss at gmail.com>
Date: Thu Feb 25 14:47:34 2016 +0100
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
>---------------------------------------------------------------
0c7db61f8a17b2c5c4335b62103eb9ffc5d24154
compiler/rename/RnExpr.hs | 2 +-
docs/users_guide/glasgow_exts.rst | 3 ++-
testsuite/tests/ado/T11607.hs | 10 ++++++++++
testsuite/tests/ado/T11607.stdout | 1 +
testsuite/tests/ado/all.T | 1 +
5 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/compiler/rename/RnExpr.hs b/compiler/rename/RnExpr.hs
index 9d1200a..ce113b4 100644
--- a/compiler/rename/RnExpr.hs
+++ b/compiler/rename/RnExpr.hs
@@ -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
diff --git a/docs/users_guide/glasgow_exts.rst b/docs/users_guide/glasgow_exts.rst
index fc7ec52..59e8b62 100644
--- a/docs/users_guide/glasgow_exts.rst
+++ b/docs/users_guide/glasgow_exts.rst
@@ -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:
diff --git a/testsuite/tests/ado/T11607.hs b/testsuite/tests/ado/T11607.hs
new file mode 100644
index 0000000..f2bb341
--- /dev/null
+++ b/testsuite/tests/ado/T11607.hs
@@ -0,0 +1,10 @@
+{-# 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
diff --git a/testsuite/tests/ado/T11607.stdout b/testsuite/tests/ado/T11607.stdout
new file mode 100644
index 0000000..1e6c1e1
--- /dev/null
+++ b/testsuite/tests/ado/T11607.stdout
@@ -0,0 +1 @@
+MaybeA (Just 42)
diff --git a/testsuite/tests/ado/all.T b/testsuite/tests/ado/all.T
index 2ec3e34..e1efdf2 100644
--- a/testsuite/tests/ado/all.T
+++ b/testsuite/tests/ado/all.T
@@ -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, [''])
More information about the ghc-commits
mailing list