From: pimjager Date: Thu, 28 Apr 2016 19:07:13 +0000 (+0200) Subject: Working on algorithm M X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=18ceb1ca835fab1e77b245bac072c718e738db4a;p=cc1516.git Working on algorithm M --- 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)