From 86511734bd44fb9025eb63db027aefb1bb465c10 Mon Sep 17 00:00:00 2001 From: pimjager Date: Fri, 29 Apr 2016 17:07:31 +0200 Subject: [PATCH] infer for FunExpr --- sem.icl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) -- 2.20.1