from Data.Func import $
from StdFunc import o, flip, const, id
+import Control.Applicative
import Control.Monad
import Control.Monad.Trans
import Control.Monad.State
_ = Left $ SanityError p "main has to return Void")
isNiceMain _ = pure ()
+unfoldLambda :: [FunDecl] -> Typing [FunDecl]
+unfoldLambda [fd:fds] = unf_ fd >>= \fds1->
+ unfoldLambda fds >>= \fds2->
+ pure $ fds1 ++ fds2
+where
+ unf_ :: FunDecl -> Typing [FunDecl]
+ unf_ fd=:(FunDecl _ _ _ _ vds stmts) =
+ flatten <$> mapM unfv_ vds >>= \fds1->
+ flatten <$> mapM unfs_ stmts >>= \fds2->
+ pure $ [fd:fds1] ++ fds2
+ unfv_ :: VarDecl -> Typing [FunDecl]
+ unfv_ (VarDecl _ _ _ e) = pure []
+ unfs_ :: Stmt -> Typing [FunDecl]
+ unfs_ _ = pure []
+
class Typeable a where
ftv :: a -> [TVar]
subst :: Substitution a -> a
infer e2 >>= \(s2, t2, e2_) ->
pure (compose s2 s1, TupleType (t1,t2), TupleExpr p (e1_,e2_))
+ LambdaExpr _ _ _ = liftT $ Left $ Error "PANIC: lambdas should be Unfolded"
+
FunExpr p f args fs =
lookup f >>= \expected ->
let accST = (\(s,ts,es) e->infer e >>= \(s_,et,e_)-> pure (compose s_ s,ts++[et],es++[e_])) in