repositories
/
cc1516.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
76d648b
)
hi
author
Mart Lubbers
<mart@martlubbers.net>
Thu, 14 Apr 2016 07:06:27 +0000
(09:06 +0200)
committer
Mart Lubbers
<mart@martlubbers.net>
Thu, 14 Apr 2016 07:06:27 +0000
(09:06 +0200)
sem.icl
patch
|
blob
|
history
diff --git
a/sem.icl
b/sem.icl
index
06200b1
..
f3d28c2
100644
(file)
--- a/
sem.icl
+++ b/
sem.icl
@@
-70,7
+70,8
@@
semFunDecl fd=:(FunDecl p f args mt vds stmts) =
inferReturnType :: [Stmt] -> Env Type
inferReturnType [] = pure VoidType
inferReturnType :: [Stmt] -> Env Type
inferReturnType [] = pure VoidType
-inferReturnType [ReturnStmt (Just t):rest] = typeExpr t
+inferReturnType [ReturnStmt (Just t):rest] = typeExpr t
+ >>= \tx->inferReturnType rest >>= \ty->unify tx ty
inferReturnType [ReturnStmt _:rest] = pure VoidType
inferReturnType [_:rest] = inferReturnType rest
inferReturnType [ReturnStmt _:rest] = pure VoidType
inferReturnType [_:rest] = inferReturnType rest
@@
-200,6
+201,8
@@
instance unify Type where
unify (ListType t1) (ListType t2) = unify t1 t2 >>| (pure $ ListType t1)
unify (ta1 ->> ta2) (tb1 ->> tb2) = unify ta1 tb1 >>= \ta-> unify ta2 tb2
>>= \tb-> pure (ta ->> tb)
unify (ListType t1) (ListType t2) = unify t1 t2 >>| (pure $ ListType t1)
unify (ta1 ->> ta2) (tb1 ->> tb2) = unify ta1 tb1 >>= \ta-> unify ta2 tb2
>>= \tb-> pure (ta ->> tb)
+ unify VoidType t = pure t
+ unify t VoidType = pure t
unify VoidType VoidType = pure VoidType
unify t1 t2 = liftT $ Left $ UnifyError zero t1 t2
unify VoidType VoidType = pure VoidType
unify t1 t2 = liftT $ Left $ UnifyError zero t1 t2