From 0503dcb2998ab9dcd0f39e6f264f482a3d2cc7f7 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 25 Jul 2020 21:51:37 +0200 Subject: Support Let --- typecheck/CC/Typecheck.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'typecheck') diff --git a/typecheck/CC/Typecheck.hs b/typecheck/CC/Typecheck.hs index 8678771..8803a62 100644 --- a/typecheck/CC/Typecheck.hs +++ b/typecheck/CC/Typecheck.hs @@ -87,6 +87,8 @@ instance Substitute Env where instance Substitute T.Expr where theta >>! T.Lam ty (T.Occ name ty2) body = T.Lam (theta >>! ty) (T.Occ name (theta >>! ty2)) (theta >>! body) + theta >>! T.Let (T.Occ name ty) rhs body = + T.Let (T.Occ name (theta >>! ty)) (theta >>! rhs) (theta >>! body) theta >>! T.Call ty e1 e2 = T.Call (theta >>! ty) (theta >>! e1) (theta >>! e2) _ >>! expr@(T.Int _) = expr @@ -152,6 +154,12 @@ infer env expr = case expr of let argType = theta >>! argVar return (theta, T.Lam (T.TFun argType (T.exprType body')) (T.Occ arg argType) body') + S.Let _ (name, _) rhs body -> do + (theta1, rhs') <- infer env rhs + let varType = T.exprType rhs' + let augEnv = envAdd name (T.TypeScheme [] varType) env + (theta2, body') <- infer augEnv body + return (theta2 <> theta1, T.Let (T.Occ name varType) rhs' body') S.Call sr func arg -> do (theta1, func') <- infer env func (theta2, arg') <- infer (theta1 >>! env) arg -- cgit v1.2.3-70-g09d2