From: Mart Lubbers Date: Sun, 10 Apr 2016 19:37:58 +0000 (+0200) Subject: add type of vardecl expr to gamma X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=7a0e15a68547d29a87dd0c56d6f5a731d0cd67aa;p=cc1516.git add type of vardecl expr to gamma --- diff --git a/sem.icl b/sem.icl index 7132135..1a2ed00 100644 --- a/sem.icl +++ b/sem.icl @@ -61,21 +61,19 @@ semFunDecl f = pure $ Right f 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))