instance unfoldL_ Expr where
unfoldL_ (LambdaExpr p args e) =
fresh >>= \(IdType n) ->
- let f = ("lambda_"+++n) in
+ let f = ("2lambda_"+++n) in
let fd = FunDecl p f args Nothing [] [ReturnStmt $ Just e] in
let fe = FunExpr p f [] [] in
pure ([fd], fe)
lookup f >>= \expected ->
let accST = (\(s,ts,es) e->infer e >>= \(s_,et,e_)-> pure (compose s_ s,ts++[et],es++[e_])) in
foldM accST (zero,[],[]) args >>= \(s1, argTs, args_)->
+ (case f of
+ "print" = case head argTs of
+ IntType = pure "1printint"
+ CharType = pure "1printchar"
+ BoolType = pure "1printbool"
+ ListType (CharType) = pure "1printstr"
+ t = liftT $ Left $ SanityError p ("can not print " +++ toString t)
+ _ = pure f
+ ) >>= \newF->
fresh >>= \tv->case expected of
- FuncType t = pure (s1, t, e)
+ FuncType t = pure (s1, t, (FunExpr p newF args fs))
_ = (let given = foldr (->>) tv argTs in
lift (unify expected given) >>= \s2->
let fReturnType = subst s2 tv in
foldM foldFieldSelectors fReturnType fs >>= \returnType ->
- (case f of
- "print" = case head argTs of
- IntType = pure "1printint"
- CharType = pure "1printchar"
- BoolType = pure "1printbool"
- ListType (CharType) = pure "1printstr"
- t = liftT $ Left $ SanityError p ("can not print " +++ toString t)
- _ = pure f) >>= \newF->
pure (compose s2 s1, returnType, FunExpr p newF args_ fs))
IntExpr _ _ = pure $ (zero, IntType, e)
pure (compose s2 s1, VoidType, FunStmt newF args_ fs)
ReturnStmt Nothing = pure (zero, VoidType, s)
- ReturnStmt (Just e) = infer e >>= \(sub, t, _)-> pure (sub, t, s)
+ ReturnStmt (Just e) = infer e >>= \(sub, t, e_)-> pure (sub, t, ReturnStmt (Just e_))
reverseFs :: Type FieldSelector -> Typing Type
reverseFs t FieldHd = pure $ ListType t