Safe Haskell | None |
---|---|
Language | Haskell2010 |
Module containing typechecking functions and data structures.
- class Typecheckable term t where
- type TypingContext term t :: *
- type TypeError term t :: *
- class Typecheckable term t => Inferable term t where
- type InferenceContext term t :: *
- type InferError term t :: *
- type Typecheck term t = ExceptT [TypeError term t] (State (TypingContext term t))
- runTypecheck :: st -> ExceptT e (State st) t -> Either e (st, t)
- expression :: forall env expr err expr. Lens (ErrorContext env expr err) (ErrorContext env expr err) [expr] [expr]
- environment :: forall env expr err env. Lens (ErrorContext env expr err) (ErrorContext env expr err) env env
- (<><>) :: (Semigroup s1, Semigroup s2) => Either s1 s2 -> Either s1 s2 -> Either s1 s2
- data ErrorContext env expr err = ErrorContext {
- _expression :: [expr]
- _environment :: env
- _errorOfContext :: err
- type ErrorContext' term t err = ErrorContext (TypingContext term t) (term t) err
- throwErrorContext :: (MonadError [ErrorContext env expr err] m, MonadState env m) => [expr] -> err -> m b
- throwErrorContexts :: (MonadError (f (ErrorContext env expr err)) m, MonadState env m, Functor f) => f ([expr], err) -> m b
- errorOfContext :: forall env expr err err. Lens (ErrorContext env expr err) (ErrorContext env expr err) err err
- appendExprToEContexts :: (MonadError (f (ErrorContext env expr err)) m, Functor f) => expr -> m a -> m a
Typeclasses for Typechecking and Inference
class Typecheckable term t where Source #
A typeclass for typechecking terms (term
) with a typesystem (t
).
type TypingContext term t :: * Source #
The typing context, in type theory this is usually shown as 𝚪.
For a basic typechecker of the simply-typed lambda calculus this might contain a mapping of variable and constant names to their types. This is left to be defined for the implementer though as other typesystems might need extra information in their contexts.
type TypeError term t :: * Source #
The type error representation.
typecheck :: TypingContext term t -> term t -> Either [TypeError term t] (TypingContext term t, t) Source #
Given a typing context, typecheck an expression and either return a typeerror or the type of the expression that was passed.
(Ord m, Ord c, Ord v) => Typecheckable (LambdaTerm c v) (SimplyTyped m) Source # | |
(Ord c, Ord v, Ord m, Ord p) => Typecheckable (LambdaTerm c v) (SystemF m p) Source # | |
class Typecheckable term t => Inferable term t where Source #
type InferenceContext term t :: * Source #
The inference context, has a similar function to TypingContext
type InferError term t :: * Source #
The inference error representation.
infer :: InferenceContext term t -> term (Maybe t) -> Either [InferError term t] (InferenceContext term t, term t) Source #
typingContext :: InferenceContext term t -> TypingContext term t Source #
Get a typing context from an inference context.
Typing context and Type error structures
General use
type Typecheck term t = ExceptT [TypeError term t] (State (TypingContext term t)) Source #
Typechecking type, uses the TypingContext as state and TypeError as an exception type.
expression :: forall env expr err expr. Lens (ErrorContext env expr err) (ErrorContext env expr err) [expr] [expr] Source #
environment :: forall env expr err env. Lens (ErrorContext env expr err) (ErrorContext env expr err) env env Source #
(<><>) :: (Semigroup s1, Semigroup s2) => Either s1 s2 -> Either s1 s2 -> Either s1 s2 Source #
A validation semigroup on Eithers, combining Left values when two appear.
ErrorContext
data ErrorContext env expr err Source #
Data type for an error context, holding the expression where the error occurred, the environment when it did, and the error itself.
ErrorContext | |
|
type ErrorContext' term t err = ErrorContext (TypingContext term t) (term t) err Source #
ErrorContext but the environment is assumed to be the TypingContext of t
.
throwErrorContext :: (MonadError [ErrorContext env expr err] m, MonadState env m) => [expr] -> err -> m b Source #
Throw an error in an ErrorContext
.
throwErrorContexts :: (MonadError (f (ErrorContext env expr err)) m, MonadState env m, Functor f) => f ([expr], err) -> m b Source #
Throw a list of errors in ErrorContext
's.
errorOfContext :: forall env expr err err. Lens (ErrorContext env expr err) (ErrorContext env expr err) err err Source #
appendExprToEContexts :: (MonadError (f (ErrorContext env expr err)) m, Functor f) => expr -> m a -> m a Source #
If there have been any errors, add the given expression to the head of all the error contexts' expression stacks.