libcspm-0.2.0: A library providing a parser, type checker and evaluator for CSPM.

CSPM.TypeChecker.Monad

Synopsis

Documentation

getType :: Name -> TypeCheckMonad TypeSchemeSource

Get the type of n and throw an exception if it doesn't exist.

setType :: Name -> TypeScheme -> TypeCheckMonad ()Source

Sets the type of n to be t in the current scope only. No unification is performed.

compress :: Type -> TypeCheckMonad TypeSource

Takes a type and compresses the type by reading all type variables and if they point to another type, it returns that type instead.

compressTypeScheme :: TypeScheme -> TypeCheckMonad TypeSchemeSource

Apply compress to the type of a type scheme.

runTypeChecker :: TypeInferenceState -> TypeCheckMonad a -> IO aSource

Runs the typechecker, starting from state st. If any errors are encountered then a SourceError will be thrown with the relevent error messages.

data TypeInferenceState Source

Constructors

TypeInferenceState 

Fields

environment :: Environment

The type environment, which is a map from names to types.

dataTypesAndChannels :: [Name]

List of names that correspond to channels and datatypes - used when detecting dependencies.

srcSpan :: SrcSpan

Location of the current AST element - used for error pretty printing

errorContexts :: [ErrorContext]

Error stack - provides context information for any errors that might be raised

errors :: [ErrorMessage]

Errors that have occured

warnings :: [ErrorMessage]

List of warnings that have occured

unificationStack :: [(Type, Type)]

Stack of attempted unifications - the current one is at the front. In the form (expected, actual).

inError :: Bool

Are we currently in an error state

symUnificationAllowed :: Bool
 

setSrcSpan :: SrcSpan -> TypeCheckMonad a -> TypeCheckMonad aSource

Sets the SrcSpan only within prog.

raiseMessagesAsError :: [Error] -> TypeCheckMonad aSource

Report a message as an error

panic :: String -> aSource

Given a string causes a Panic to be thrown.

errorIfFalse :: Bool -> Error -> TypeCheckMonad ()Source

Report the error if first parameter is False.