curry gotcha
[cc1516.git] / sem.icl
diff --git a/sem.icl b/sem.icl
index eef2974..448c67e 100644 (file)
--- a/sem.icl
+++ b/sem.icl
@@ -202,7 +202,7 @@ unify (ta1->>ta2) (tb1->>tb2) = unify ta1 tb1 >>= \s1->
                                 unify (subst s1 ta2) (subst s1 tb2) >>= \s2->
                                 Right $ compose s2 s1
 unify (TupleType (ta1,ta2)) (TupleType (tb1,tb2)) = unify ta1 tb1 >>= \s1->
-                                                    unify ta2 tb2 >>= \s2->
+                                                    unify (subst s1 ta2) (subst s1 tb2) >>= \s2->
                                                     Right $ compose s2 s1
 unify (ListType t1) (ListType t2) = unify t1 t2
 unify (FuncType t1) (FuncType t2) = unify t1 t2
@@ -308,8 +308,8 @@ instance infer Expr where
             _ = pure f
         ) >>= \newF->
         fresh >>= \tv->case expected of
-            FuncType t = pure (s1, t, (FunExpr p newF args fs))
-                //TODO: Fieldselectors!
+            FuncType t = foldM foldFieldSelectors t fs >>= \returnType ->
+                pure (s1, returnType, (FunExpr p newF args fs))
             _ = (let given = foldr (->>) tv argTs in
                 lift (unify expected given) >>= \s2->
                 applySubst s2 >>|
@@ -405,7 +405,7 @@ instance infer Stmt where
 
 reverseFs :: Type FieldSelector -> Typing Type 
 reverseFs t FieldHd = pure $ ListType t
-reverseFs t FieldTl = pure $ ListType 
+reverseFs t FieldTl = pure t 
 reverseFs t FieldFst = fresh >>= \tv -> pure $ TupleType (t, tv)
 reverseFs t FieldSnd = fresh >>= \tv -> pure $ TupleType (tv, t)