definition module AST
from Data.Maybe import :: Maybe
-from StdOverloaded import class toString, class ==
+from StdOverloaded import class toString, class ==, class <
:: Pos = {line :: Int, col :: Int}
:: AST = AST [FunDecl]
instance toString Pos
instance toString Type
instance toString AST
+instance == Op1
+instance == Op2
+instance < Op1
+instance < Op2
BiLesserEq = "<="; BiGreaterEq = ">="; BiUnEqual = "!=";
BiAnd = "&&"; BiOr = "||"; BiCons = ":"
+instance toString Op1 where
+ toString UnNegation = "!"
+ toString UnMinus = "-"
+
instance print Expr where
print (VarExpr _ vd) = print vd
print (Op2Expr _ e1 o e2) = ["(":print e1] ++
derive gEq Op2
instance == Op2 where (==) o1 o2 = gEq{|*|} o1 o2
+
+derive gEq Op1
+instance == Op1 where (==) o1 o2 = gEq{|*|} o1 o2
+
+instance < Op2 where
+ (<) o1 o2 = (toString o1) < (toString o2)
+
+instance < Op1 where
+ (<) o1 o2 = (toString o1) < (toString o2)
\ No newline at end of file
import qualified Data.Map as Map
from Data.Func import $
-from StdFunc import o
+from StdFunc import o, id
import Control.Monad
import Data.Either
import Data.Monoid
+import Data.List
import StdString
import StdList
where
scope e = 'Map'.put x sc ('Map'.del x e )
+fresh :: Infer Type
+fresh = (gets id) >>= \vars-> (put $ tail vars) >>| (pure $ IdType $ head vars)
+
class infer a :: a -> Infer Type
+op2Type :: Op2 -> Infer Type
+op2Type op | elem op [BiPlus, BiMinus, BiTimes, BiDivide, BiMod]
+ = pure (IntType ->> IntType ->> IntType)
+ | elem op [BiEquals, BiUnEqual]
+ = fresh >>= \t1-> fresh >>= \t2-> pure (t1 ->> t2 ->> BoolType)
+ | elem op [BiLesser, BiGreater, BiLesserEq, BiGreaterEq]
+ = pure (IntType ->> IntType ->> BoolType)
+ | elem op [BiAnd, BiOr]
+ = pure (BoolType ->> BoolType ->> BoolType)
+ | op == BiCons
+ = fresh >>= \t1-> pure (t1 ->> ListType t1 ->> ListType t1)
+
instance infer Expr where
infer (VarExpr _ vd) = undef
infer (Op2Expr _ e1 op e2) = case op of