Commit 154d224a authored by Matthew Pickering's avatar Matthew Pickering Committed by Ben Gamari
Browse files

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
parent 04ea4c3f
......@@ -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]
......
{-# 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
......@@ -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, [''])
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