Safe Haskell | Safe |
---|
- type TyEnv = Map VarName Ty
- isSubtype :: Ty -> Ty -> Bool
- isSupertype :: Ty -> Ty -> Bool
- commonSupertype :: Ty -> Ty -> Ty
- commonSubtype :: Ty -> Ty -> Ty
- tyFIXME :: Ty
- checkTypeof :: String -> Doc
- typeError :: Expr -> Ty -> Ty -> Fallible a
- typeofExprWantBool :: TyEnv -> Expr -> Fallible Ty
- typeofExprWantString :: TyEnv -> Expr -> Fallible Ty
- typeofExprWantNumber :: TyEnv -> Expr -> Fallible Ty
- typeofExprWantList :: TyEnv -> Expr -> Fallible Ty
- typeofExprWantFunction :: TyEnv -> Expr -> Fallible Ty
- typeofExprWantTuple :: Int -> TyEnv -> Expr -> Fallible Ty
- typeofExprWantTy :: Ty -> TyEnv -> Expr -> Fallible Ty
- typeofExprBounded :: Ty -> Ty -> TyEnv -> Expr -> Fallible Ty
- typeofExpr :: TyEnv -> Expr -> Fallible Ty
- genStringizer :: Ty -> Expr
Documentation
isSupertype :: Ty -> Ty -> Bool #
Returns True when x is a supertype of y (i.e, when y is a subtype of x).
commonSupertype :: Ty -> Ty -> Ty #
Returns a type that is a supertype of both x and y; the type it returns is the "least upper bound" (⊔) of x and y. Because Moses has pairs and functions, the type returned may not be equal to either of the supplied types. In the worst case, everything falls under the supertype ANY.
commonSubtype :: Ty -> Ty -> Ty #
Returns a type that is a subtype of both x and y; the type it returns is the "greatest lower bound" (⊓) of x and y. Because Moses has pairs and functions, the type returned may not be equal to either of the supplied types. In the worst case, everything is above the subtype NONE.
TODO: You can remove this definition when you've implemented commonSupertype and commonSubtype.
checkTypeof :: String -> Doc #
You can manually use checkTypeof to enter expressions and check their types, e.g, checkTypeof "42" checkTypeof "1+1"
typeofExprWantBool :: TyEnv -> Expr -> Fallible Ty #
Given a typing environment and an expression, typechecks the expression AND
makes sure that the resulting type is BoolTy
(or else fails).
typeofExprWantString :: TyEnv -> Expr -> Fallible Ty #
Given a typing environment and an expression, typechecks the expression AND
makes sure that the resulting type is StringTy
(or else fails).
typeofExprWantList :: TyEnv -> Expr -> Fallible Ty #
Given a typing environment and an expression, typechecks the expression AND
makes sure that the resulting type is some kind of list: ListTy
elemTy
(or else fails).
typeofExprWantFunction :: TyEnv -> Expr -> Fallible Ty #
Given a typing environment and an expression, typechecks the expression AND
makes sure that the resulting type is some kind of function: FunTy
argTy resTy
(or else fails).
typeofExprWantTuple :: Int -> TyEnv -> Expr -> Fallible Ty #
Given a size n, a typing environment, and an expression, typechecks the expression AND
makes sure that the resulting type is some kind of tuple of size n: TupleTy
tyList
where tyList has size n (or else fails).
typeofExprWantTy :: Ty -> TyEnv -> Expr -> Fallible Ty #
Given an expected type ty, a typing environment, and an expression, typechecks the expression AND makes sure that the resulting type is exactly ty (or else fails).
typeofExprBounded :: Ty -> Ty -> TyEnv -> Expr -> Fallible Ty #
A general version of bounded type checking, used by other helper functions to provide constraints on the type of an expression.
The call
typeofExprBounded lowerTy upperTy tenv expr
typeofExpr :: TyEnv -> Expr -> Fallible Ty #
Given a typing environment and an expression, checks that the expression is well typed. This is the main typechecking function.
genStringizer :: Ty -> Expr #
Determine how to display a value of a given type.