Made binds keep args instead of lambda converting

This commit is contained in:
sebastian 2023-03-23 22:07:55 +01:00
parent 0012efabb7
commit fc60112877
3 changed files with 18 additions and 13 deletions

View file

@ -33,6 +33,8 @@ executable language
Auxiliary
TypeChecker.TypeChecker
TypeChecker.TypeCheckerIr
Monomorphizer.Monomorphizer
Monomorphizer.MonomorphizerIr
Renamer.Renamer
Codegen.Codegen
Codegen.LlvmIr

View file

@ -106,18 +106,20 @@ checkPrg (Program bs) = do
checkBind :: Bind -> Infer T.Bind
checkBind (Bind name args e) = do
let lambda = makeLambda e (reverse $ coerce args)
e@(_, t') <- inferExp lambda
s <- gets sigs
case M.lookup (coerce name) s of
Just (Just t) -> do
sub <- unify t t'
let newT = apply sub t
insertSig (coerce name) (Just newT)
return $ T.Bind (coerce name, newT) [] e
_ -> do
insertSig (coerce name) (Just t')
return (T.Bind (coerce name, t') [] e) -- (apply s e)
-- let lambda = makeLambda e (reverse $ coerce args)
args <- zip args <$> mapM (const fresh) args
withBindings (map coerce args) $ do
e@(_, t') <- inferExp e
s <- gets sigs
case M.lookup (coerce name) s of
Just (Just t) -> do
sub <- unify t t'
let newT = apply sub t
insertSig (coerce name) (Just newT)
return $ T.Bind (coerce name, newT) (map coerce args) e
_ -> do
insertSig (coerce name) (Just t')
return (T.Bind (coerce name, t') (map coerce args) e) -- (apply s e)
where
makeLambda :: Exp -> [Ident] -> Exp
makeLambda = foldl (flip (EAbs . coerce))

View file

@ -93,7 +93,7 @@ instance Print Program where
prt i (Program sc) = prPrec i 0 $ prt 0 sc
instance Print Bind where
prt i (Bind (name, t) _ rhs) =
prt i (Bind (name, t) args rhs) =
prPrec i 0 $
concatD
[ prt 0 name
@ -101,6 +101,7 @@ instance Print Bind where
, prt 0 t
, doc $ showString "\n"
, prt 0 name
, prtIdPs 0 args
, doc $ showString "="
, prt 0 rhs
]