[commit: ghc] master: Allow operators as record pattern synonym fields (154d224)
git at git.haskell.org
git at git.haskell.org
Wed Mar 29 20:53:44 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/154d224ade3d9f22b0e22fc8be8f3907f1ad51d2/ghc
>---------------------------------------------------------------
commit 154d224ade3d9f22b0e22fc8be8f3907f1ad51d2
Author: Matthew Pickering <matthewtpickering at gmail.com>
Date: Wed Mar 29 16:09:08 2017 -0400
Allow operators as record pattern synonym fields
Fixes #13454
Reviewers: austin, bgamari, dfeuer
Reviewed By: dfeuer
Subscribers: RyanGlScott, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3379
>---------------------------------------------------------------
154d224ade3d9f22b0e22fc8be8f3907f1ad51d2
compiler/parser/Parser.y | 4 ++--
testsuite/tests/patsyn/should_compile/T13454.hs | 15 +++++++++++++++
testsuite/tests/patsyn/should_compile/all.T | 1 +
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/compiler/parser/Parser.y b/compiler/parser/Parser.y
index caa22dc..21f564e 100644
--- a/compiler/parser/Parser.y
+++ b/compiler/parser/Parser.y
@@ -1362,8 +1362,8 @@ vars0 :: { [Located RdrName] }
| varid vars0 { $1 : $2 }
cvars1 :: { [RecordPatSynField (Located RdrName)] }
- : varid { [RecordPatSynField $1 $1] }
- | varid ',' cvars1 {% addAnnotation (getLoc $1) AnnComma (getLoc $2) >>
+ : var { [RecordPatSynField $1 $1] }
+ | var ',' cvars1 {% addAnnotation (getLoc $1) AnnComma (getLoc $2) >>
return ((RecordPatSynField $1 $1) : $3 )}
where_decls :: { Located ([AddAnn]
diff --git a/testsuite/tests/patsyn/should_compile/T13454.hs b/testsuite/tests/patsyn/should_compile/T13454.hs
new file mode 100644
index 0000000..88a5441
--- /dev/null
+++ b/testsuite/tests/patsyn/should_compile/T13454.hs
@@ -0,0 +1,15 @@
+{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
+module T13454 where
+
+pattern MkOp :: Op -> Exp -> Exp -> Exp
+pattern MkOp {(·), a, b} <- (splitOp -> Just ((·), a, b))
+ where MkOp (·) a b = a · b
+
+data Exp = Val Int | Add Exp Exp | Mul Exp Exp deriving Show
+
+type Op = Exp -> Exp -> Exp
+
+splitOp :: Exp -> Maybe (Op, Exp, Exp)
+splitOp (Add a b) = Just (Add, a, b)
+splitOp (Mul a b) = Just (Mul, a, b)
+splitOp _ = Nothing
diff --git a/testsuite/tests/patsyn/should_compile/all.T b/testsuite/tests/patsyn/should_compile/all.T
index 8fce7e9..fa8a3d8 100644
--- a/testsuite/tests/patsyn/should_compile/all.T
+++ b/testsuite/tests/patsyn/should_compile/all.T
@@ -67,3 +67,4 @@ test('T13349b', normal, compile, [''])
test('T13441', normal, compile, [''])
test('T13441a', normal, compile, [''])
test('T13441b', normal, compile_fail, [''])
+test('T13454', normal, compile, [''])
More information about the ghc-commits
mailing list