diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-07-25 21:51:37 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-07-25 21:51:37 +0200 |
commit | 0503dcb2998ab9dcd0f39e6f264f482a3d2cc7f7 (patch) | |
tree | deb942a011451b183a1028a2f0f891d9e09e5107 /typecheck/CC | |
parent | d5ab8f4939a4af51c7a9e1c2cd73c8352f8345b4 (diff) |
Support Let
Diffstat (limited to 'typecheck/CC')
-rw-r--r-- | typecheck/CC/Typecheck.hs | 8 |
1 files changed, 8 insertions, 0 deletions
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 |