Safe Haskell | Safe |
---|
Stlc.Types
- data Type
- typeinference :: Exp -> Maybe Type
- typeinfer :: [Variable] -> Context -> Exp -> Type -> Maybe Substitution
- unify :: Type -> Type -> Maybe Substitution
- applyctx :: Substitution -> Context -> Context
- emptyctx :: Context
- incrementindices :: Context -> Context
- variables :: [Variable]
- normalizeTemplate :: Map Integer Integer -> Integer -> Type -> (Map Integer Integer, Integer)
- applynormalization :: Map Integer Integer -> Type -> Type
- newtype Top = Top Type
- type Context = Map Integer Type
- type Variable = Integer
- type Substitution = Type -> Type
Documentation
A type template is a free type variable or an arrow between two types; that is, the function type.
typeinference :: Exp -> Maybe Type Source #
Type inference of a lambda expression.
Arguments
:: [Variable] | List of fresh variables |
-> Context | Type context |
-> Exp | Lambda expression whose type has to be inferred |
-> Type | Constraint |
-> Maybe Substitution |
Type inference algorithm. Infers a type from a given context and expression with a set of constraints represented by a unifier type. The result type must be unifiable with this given type.
unify :: Type -> Type -> Maybe Substitution Source #
Unifies two types with their most general unifier. Returns the substitution that transforms any of the types into the unifier.
applyctx :: Substitution -> Context -> Context Source #
Apply a substitution to all the types on a type context.
incrementindices :: Context -> Context Source #
Increments all the indices of a given context. It is useful for adapting the context to a new scope.
normalizeTemplate :: Map Integer Integer -> Integer -> Type -> (Map Integer Integer, Integer) Source #
Substitutes a set of type variables on a type template for the smaller possible ones.
applynormalization :: Map Integer Integer -> Type -> Type Source #
Applies a set of variable substitutions to a type to normalize it.
type Context = Map Integer Type Source #
A type context is a map from deBruijn indices to types. Given any lambda variable as a deBruijn index, it returns its type.
type Substitution = Type -> Type Source #
A type substitution is a function that can be applied to any type to get a new one.