From 18ceb1ca835fab1e77b245bac072c718e738db4a Mon Sep 17 00:00:00 2001 From: pimjager Date: Thu, 28 Apr 2016 21:07:13 +0200 Subject: [PATCH] Working on algorithm M --- sem.icl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sem.icl b/sem.icl index 8cc3df9..1e9846d 100644 --- a/sem.icl +++ b/sem.icl @@ -204,6 +204,7 @@ instance infer Expr where infer e = case e of VarExpr _ (VarDef k fs) = (\t->(zero,t)) <$> (lookup k >>= instantiate) //instantiate is key for the let polymorphism! + //TODO: field selectors Op2Expr _ e1 op e2 = infer e1 >>= \(s1, t1) -> @@ -220,9 +221,18 @@ instance infer Expr where let given = t1 ->> tv in op1Type op >>= \expected -> lift (unify expected given) >>= \s2 -> - pure ((compose s1 s2), subst s2 tv) + pure (compose s1 s2, subst s2 tv) + EmptyListExpr _ = (\tv->(zero,tv)) <$> fresh + TupleExpr _ (e1, e2) = + infer e1 >>= \(s1, t1) -> + infer e2 >>= \(s2, t2) -> + pure (compose s1 s2, TupleType (t1,t2)) + + FunExpr _ f args fs = //todo: fieldselectors + lookup f >>= \expected -> + mapM infer args >>= \argTypes IntExpr _ _ = pure $ (zero, IntType) BoolExpr _ _ = pure $ (zero, BoolType) -- 2.20.1