added PEnum

This commit is contained in:
sebastianselander 2023-03-24 17:39:10 +01:00
parent d6d0fb7146
commit 41fc863658
5 changed files with 43 additions and 20 deletions

View file

@ -562,6 +562,7 @@ withPattern p ma = case p of
T.PInj _ ps -> foldl' (flip withPattern) ma ps
T.PLit _ -> ma
T.PCatch -> ma
T.PEnum _ -> ma
inferPattern :: Pattern -> Infer (T.Pattern, T.Type)
inferPattern = \case
@ -574,6 +575,10 @@ inferPattern = \case
zipWithM_ unify vs (map snd patterns)
return (T.PInj (coerce constr) (map fst patterns), ret)
PCatch -> (T.PCatch,) <$> fresh
PEnum p -> do
t <- gets (M.lookup (coerce p) . constructors)
t <- maybeToRightM ("Constructor: " <> printTree p <> " does not exist") t
return (T.PEnum $ coerce p, t)
PVar x -> do
fr <- fresh
let pvar = T.PVar (coerce x, fr)

View file

@ -64,7 +64,7 @@ type ExpT = (Exp, Type)
data Branch = Branch (Pattern, Type) ExpT
deriving (C.Eq, C.Ord, C.Read, C.Show)
data Pattern = PVar Id | PLit (Lit, Type) | PInj Ident [Pattern] | PCatch
data Pattern = PVar Id | PLit (Lit, Type) | PInj Ident [Pattern] | PCatch | PEnum Ident
deriving (C.Eq, C.Ord, C.Show, C.Read)
data Def = DBind Bind | DData Data