From: pimjager Date: Fri, 29 Apr 2016 15:07:31 +0000 (+0200) Subject: infer for FunExpr X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=86511734bd44fb9025eb63db027aefb1bb465c10;p=cc1516.git infer for FunExpr --- diff --git a/sem.icl b/sem.icl index 1e9846d..fa4b3ae 100644 --- a/sem.icl +++ b/sem.icl @@ -231,8 +231,13 @@ instance infer Expr where pure (compose s1 s2, TupleType (t1,t2)) FunExpr _ f args fs = //todo: fieldselectors - lookup f >>= \expected -> - mapM infer args >>= \argTypes + lookup f >>= instantiate >>= \expected -> + let accTypSub = (\(s,ts) e->infer e >>= \(s_,et)->pure (compose s_ s,ts++[et])) in + foldM accTypSub (zero,[]) args >>= \(s1, argTs)-> + fresh >>= \tv-> + let given = foldr (->>) tv argTs in + lift (unify expected given) >>= \s2-> + pure (compose s1 s2, subst s2 tv) IntExpr _ _ = pure $ (zero, IntType) BoolExpr _ _ = pure $ (zero, BoolType)