semVarDecl :: VarDecl -> Env VarDecl
semVarDecl vd=:(VarDecl pos type ident ex) = unify type ex
- >>= \et->pure (
- et >>= \t->pure $ VarDecl pos t ident ex)
+ >>= \et->case et of
+ Left err = pure $ Left err
+ Right t = putIdent ident t >>| pure (Right $ VarDecl pos t ident ex)
//Right v
// //TODO ident in de environment
// Right e = Right $ pure vd
-typeOp1 :: Pos Expr Type -> Env Type
-typeOp1 p expr rtype = unify rtype expr
-
typeExpr :: Expr -> Env Type
typeExpr (IntExpr _ _) = pure $ Right IntType
typeExpr (CharExpr _ _) = pure $ Right CharType
typeExpr (BoolExpr _ _) = pure $ Right BoolType
-typeExpr (Op1Expr p UnNegation expr) = typeOp1 p expr BoolType
-typeExpr (Op1Expr p UnMinus expr) = typeOp1 p expr IntType
+typeExpr (Op1Expr p UnNegation expr) = unify BoolType expr
+typeExpr (Op1Expr p UnMinus expr) = unify IntType expr
typeExpr (TupleExpr p (e1, e2)) = typeExpr e1
>>= \ete1->typeExpr e2 >>= \ete2->pure (
ete1 >>= \te1->ete2 >>= \te2->Right $ TupleType (te1, te2))