Small improvements, some errors here and there
[cc1516.git] / sem.icl
diff --git a/sem.icl b/sem.icl
index 791ae69..7f7cdf4 100644 (file)
--- a/sem.icl
+++ b/sem.icl
@@ -222,7 +222,6 @@ instance infer Expr where
         pure ((compose s3 $ compose s2 s1), subst s3 tv)
 
     Op1Expr _ op e1 =
-        abort "infereing op1" >>|
         infer e1 >>= \(s1, t1) -> 
         fresh >>= \tv ->
         let given = t1 ->> tv in 
@@ -230,10 +229,9 @@ instance infer Expr where
         lift (unify expected given) >>= \s2 ->
         pure (compose s2 s1, subst s2 tv)
 
-    EmptyListExpr _ = abort "infereing []" >>| (\tv->(zero,tv)) <$> fresh
+    EmptyListExpr _ = (\tv->(zero,tv)) <$> fresh
 
     TupleExpr _ (e1, e2) = 
-        abort "infereing (,)" >>|
         infer e1 >>= \(s1, t1) -> 
         infer e2 >>= \(s2, t2) ->
         pure (compose s2 s1, TupleType (t1,t2))
@@ -242,7 +240,6 @@ instance infer Expr where
         lookup f >>= \expected ->
         let accST = (\(s,ts) e->infer e >>= \(s_,et)->pure (compose s_ s,ts++[et])) in
         foldM accST (zero,[]) args >>= \(s1, argTs)->
-        //abort (concat (["argsTs: "] ++ (map toString argTs))) >>|
         fresh >>= \tv->
         let given = foldr (->>) tv argTs in
         lift (unify expected given) >>= \s2->
@@ -327,15 +324,17 @@ class type a :: a -> Typing a
 
 instance type VarDecl where
     type (VarDecl p expected k e) = 
-        infer e >>= \(s, given) ->
-        applySubst s >>| 
+        infer e >>= \(s1, given) ->
+        applySubst s1 >>| 
         case expected of
             Nothing = pure zero
             Just expected_ = lift (unify expected_ given)
-        >>|
-        generalize given >>= \t ->
+        >>= \s2->
+        applySubst s2 >>|
+        let vtype = subst (compose s2 s1) given in
+        generalize vtype >>= \t ->
         changeGamma (extend k t) >>| 
-        pure (VarDecl p (Just given) k e)
+        pure (VarDecl p (Just vtype) k e)
 
 instance type FunDecl where
     type (FunDecl p f args expected vds stmts) =