Portability | portable (GHC, Hugs) |
---|---|
Stability | stable |
Maintainer | f@mazzo.li |
Safe Haskell | Safe-Infered |
This module implements the W algorithm for the small language we are using.
There is one minor annoyance: The Type
datatype distinguishes between free
type variables and quantified type variable, but the exposed functions of
this module should produce types completely free of free type variables. This
could be checked statically having a separate datatype without free type
variables, but I compromised for clarity and brevity.
Partly inspired by the paper "Typing Haskell in Haskell" by Mark P. Jones, http://web.cecs.pdx.edu/~mpj/thih/.
Data types
A data type to represent types. Note that the functions of this module
should return Type
s without TyVar
s (we want the schemes to have no free
variables).
Type inference
What can go wrong when inferring the types.
UnificationFail Type Type | Unification failed (e.g. when trying to unify a quantified variable with an arrow type). |
InfiniteType TyVar Type | The user is trying to construct an infinite type, e.g. 'a = a -> b'. |
UnboundVariable Id | Unbound variable (value, not type variable). |
TypeError | Generic error, needed for the |
typeProgram :: Program -> Either TypeError ([(Id, Scheme)], Scheme)Source
Types a list of declarations (a Program
) returning the principal type for
each declaration and the type of the final expression.
Pretty printing
prettyType :: Type -> DocSource
prettyScheme :: Scheme -> DocSource