= case partition (\a->a=:(Function ['start'] _ _)) fs of
([], _) = Left ["No start function defined"]
([Function _ [] e], fs)
- # e = foldr (\(Function i a e)->Let i a e) e fs
+ # e = foldr (\(Function i a e)->Let i (mkLambda a e)) e fs
= case runInfer (infer 'Data.Map'.newMap e) of
Left e = Left e
Right s
= Left [printToString s]
([Function _ _ _], _) = Left ["Start cannot have arguments"]
+mkLambda :: [[Char]] Expression -> Expression
+mkLambda [] e = e
+mkLambda [a:as] e = Lambda a (mkLambda as e)
+
import Text.GenPrint
derive gPrint Scheme, Type
>>= \tv-> infer ('Data.Map'.put x (Forall [] tv) env) b
>>= \(s1, t1)->pure (s1, TFun (apply s1 tv) t1)
infer env (Builtin c a) = undef
-infer env (Let i args e b) = undef
+infer env (Let x e1 e2)
+ = infer env e1
+ >>= \(s1, t1)->let env` = apply s1 env in infer ('Data.Map'.put x (generalize env` t1) env) e2
+ >>= \(s2, t2)->pure (compose s1 s2, t2)