:: Gamma :== ('Map'.Map String Type, [String])
:: Env a :== StateT Gamma (Either SemError) a
+//StateT (Gamma -> Either SemError (a, Gamma))
//we need to redefine this even though it is in Control.Monad.State
instance MonadTrans (StateT Gamma) where
where
genIdents r = let (ic, r) = splitAt 5 r in [toString ic: genIdents r]
-freshIdent :: Gamma -> (String, Gamma)
-freshIdent (st, [ident:rest]) = case 'Map'.get ident st of
- Nothing = (ident, (st, rest))
- _ = freshIdent (st, rest)
+freshIdent :: Env String
+freshIdent = get >>= \(st, [ident:rest])-> put (st, rest)
+ >>| case 'Map'.get ident st of
+ Nothing = pure ident
+ _ = freshIdent
putIdent :: String Type -> Env Void
putIdent i t = gets (\(st, r)->'Map'.get i st) >>= \mt -> case mt of
mapM semFunDecl fd >>= \fds ->
pure (vds, fds)
-
-
-splitEithers :: [Either a b] -> Either [a] [b]
-splitEithers [] = Right []
-splitEithers [Right x:xs] = splitEithers xs >>= \rest->Right [x:rest]
-splitEithers xs = Left $ [x\\(Left x)<-xs]
-
semFunDecl :: FunDecl -> Env FunDecl
semFunDecl f = pure f
typeExpr (Op2Expr p e1 BiCons e2) = typeExpr e1 >>= \t1-> typeExpr e2
>>= \t2-> unify (ListType t1) t2
//typeExpr (FunExpr p FunCall) = undef
-typeExpr (EmptyListExpr p) = pure $ ListType IntType //we'll need quantified types
+typeExpr (EmptyListExpr p) = freshIdent >>= \frsh-> let t = IdType frsh in
+ putIdent frsh t >>| pure t
//typeExpr (VarExpr Pos VarDef) = undef //when checking var-expr, be sure to
//put the infered type in the context