Lambda WIP
[cc1516.git] / sem.icl
diff --git a/sem.icl b/sem.icl
index 5cf0520..9d9b5fe 100644 (file)
--- a/sem.icl
+++ b/sem.icl
@@ -88,6 +88,19 @@ where
                                _ = Left $ SanityError p "main has to return Void")
                isNiceMain _ = pure ()
 
+unfoldLambda :: [FunDecl] -> Typing [FunDecl]
+unfoldLambda [fd:fds] = unf_ fd >>= \fds1-> 
+                        unfoldLambda fds2 >>= \fds2->
+                        pure $ fds1 ++ fds2
+where
+    unf_ fd=:(FunDecl _ _ _ _ vds stmts) = 
+        mapM_ unfv_ vds >>= \fds1->
+        mapM_ unfs_ stmts >>= \fds2->
+        pure [fd:fds] ++ fds2
+    unfv_ :: Typing [FunDecl]
+    unfv_ (VarDecl _ _ _ e) = abort ""
+    unfs_ _ = abort ""
+
 class Typeable a where
     ftv :: a -> [TVar]
     subst :: Substitution a -> a
@@ -225,7 +238,7 @@ instance infer Expr where
         infer e2 >>= \(s2, t2, e2_) ->
         pure (compose s2 s1, TupleType (t1,t2), TupleExpr p (e1_,e2_))
 
-    LambdaExpr _ _ _ = liftT $ Left $ Error "PANIC: lambdas should be tasnformed"
+    LambdaExpr _ _ _ = liftT $ Left $ Error "PANIC: lambdas should be Unfolded"
 
     FunExpr p f args fs =
         lookup f >>= \expected ->