}
}
-//foldr(f, acc, xs) {
-// if(isEmpty(xs)) {
-// return acc;
-// } else {
-// return foldr(f, f(xs.hd, acc), xs.tl);
-// }
-//}
+foldr(f, acc, xs) {
+ if(isEmpty(xs)) {
+ return acc;
+ } else {
+ return foldr(f, f(xs.hd, acc), xs.tl);
+ }
+}
+
+l2(x) :: Int -> Void {
+ //return print(3);
+ var y = print(3);
+ return;
+}
main() {
- var f = \x -> x+1;
- var z = map(\x->x+1, 1:2:[]);
- //var x = foldr(plus, 0, 1:2:[]);
+ //var f = \x->print(x);
+ var z = map(\x->print(3), 1:2:[]);
+ var x = print(3);
+ //var x = foldr(\x y->x+y, 0, 1:2:[]);
//print(x);
return;
}
\ No newline at end of file
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