adt support in type inference
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
module Rlp.AltSyntax
|
||||
(
|
||||
-- * AST
|
||||
Program(..), Decl(..), ExprF(..), Pat(..)
|
||||
Program(..), Decl(..), ExprF(..), Pat(..), pattern ConP'
|
||||
, RlpExprF, RlpExpr, Binding(..), Alter(..)
|
||||
, RlpExpr', RlpExprF', AnnotatedRlpExpr', Type'
|
||||
, DataCon(..), Type(..), Kind
|
||||
@@ -18,7 +18,7 @@ module Rlp.AltSyntax
|
||||
-- * Optics
|
||||
, programDecls
|
||||
, _VarP, _FunB, _VarB
|
||||
, _TySigD, _FunD
|
||||
, _TySigD, _FunD, _DataD
|
||||
, _LetEF
|
||||
, Core.applicants1, Core.arrowStops
|
||||
|
||||
@@ -141,6 +141,20 @@ data Pat b = VarP b
|
||||
| AppP (Pat b) (Pat b)
|
||||
deriving (Eq, Show, Generic, Generic1)
|
||||
|
||||
conList :: Prism' (Pat b) (b, [Pat b])
|
||||
conList = prism' up down where
|
||||
up (b,as) = foldl AppP (ConP b) as
|
||||
down (ConP b) = Just (b, [])
|
||||
down (AppP (ConP b) as) = Just (b, go as)
|
||||
down _ = Nothing
|
||||
|
||||
go (AppP f x) = f : go x
|
||||
go p = [p]
|
||||
|
||||
pattern ConP' :: b -> [Pat b] -> Pat b
|
||||
pattern ConP' c as <- (preview conList -> Just (c,as))
|
||||
where ConP' c as = review conList (c,as)
|
||||
|
||||
deriveShow1 ''Alter
|
||||
deriveShow1 ''Binding
|
||||
deriveShow1 ''ExprF
|
||||
|
||||
Reference in New Issue
Block a user