adt support in type inference

This commit is contained in:
crumbtoo
2024-04-05 12:28:58 -06:00
parent c147b6f3db
commit 5511d70e26
3 changed files with 50 additions and 8 deletions

View File

@@ -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