| Safe Haskell | None |
|---|
Language.PureScript.TypeChecker.Monad
Description
Monads for type checking and type inference and associated data types
- data NameKind
- data TypeDeclarationKind
- data Environment = Environment {
- names :: Map (ModuleName, Ident) (Type, NameKind)
- types :: Map (ModuleName, ProperName) (Kind, TypeDeclarationKind)
- dataConstructors :: Map (ModuleName, ProperName) (Type, NameKind)
- typeSynonyms :: Map (ModuleName, ProperName) ([String], Type)
- typeClassDictionaries :: [TypeClassDictionaryInScope]
- emptyEnvironment :: Environment
- bindNames :: MonadState CheckState m => Map (ModuleName, Ident) (Type, NameKind) -> m a -> m a
- bindTypes :: MonadState CheckState m => Map (ModuleName, ProperName) (Kind, TypeDeclarationKind) -> m a -> m a
- withTypeClassDictionaries :: MonadState CheckState m => [TypeClassDictionaryInScope] -> m a -> m a
- getTypeClassDictionaries :: (Functor m, MonadState CheckState m) => m [TypeClassDictionaryInScope]
- bindLocalVariables :: (Functor m, MonadState CheckState m) => ModuleName -> [(Ident, Type)] -> m a -> m a
- bindLocalTypeVariables :: (Functor m, MonadState CheckState m) => ModuleName -> [(ProperName, Kind)] -> m a -> m a
- lookupVariable :: (Functor m, MonadState CheckState m, MonadError String m) => ModuleName -> Qualified Ident -> m Type
- lookupTypeVariable :: (Functor m, MonadState CheckState m, MonadError String m) => ModuleName -> Qualified ProperName -> m Kind
- canonicalize :: ModuleName -> Environment -> Qualified Ident -> (ModuleName, Ident)
- canonicalizeType :: ModuleName -> Environment -> Qualified ProperName -> (ModuleName, ProperName)
- data CheckState = CheckState {}
- newtype Check a = Check {
- unCheck :: StateT CheckState (Either String) a
- getEnv :: (Functor m, MonadState CheckState m) => m Environment
- putEnv :: MonadState CheckState m => Environment -> m ()
- modifyEnv :: MonadState CheckState m => (Environment -> Environment) -> m ()
- runCheck :: Check a -> Either String (a, Environment)
- guardWith :: MonadError e m => e -> Bool -> m ()
- rethrow :: MonadError e m => (e -> e) -> m a -> m a
- freshDictionaryName :: Check Int
- newtype Substitution = Substitution {
- runSubstitution :: forall t. Unifiable t => Unknown t -> t
- data SubstState = SubstState {}
- newtype SubstContext = SubstContext {}
- newtype Subst a = Subst {
- unSubst :: ReaderT SubstContext (StateT SubstState Check) a
- liftCheck :: Check a -> Subst a
- getSubstState :: Subst SubstState
- runSubst :: SubstContext -> Subst a -> Check (a, Substitution)
- substituteWith :: Typeable t => (Unknown t -> t) -> Substitution
- substituteOne :: Unifiable t => Unknown t -> t -> Substitution
- replace :: Unifiable t => Unknown t -> t -> Subst ()
- class (Typeable t, Data t, Show t) => Unifiable t where
- occursCheck :: Unifiable t => Unknown s -> t -> Subst ()
- fresh' :: Subst Int
- fresh :: Unifiable t => Subst t
- qualifyAllUnqualifiedNames :: Data d => ModuleName -> Environment -> d -> d
Documentation
The type of a name in the Environment
Constructors
| Value | A value introduced as a binding in a module |
| Extern ForeignImportType | A foreign import |
| Alias ModuleName Ident | An alias for a value in another module, introduced using an import declaration |
| LocalVariable | A local name introduced using a lambda abstraction, variable introduction or binder |
| DataConstructor | A data constructor |
data TypeDeclarationKind Source
The type of a type declaration
Constructors
| Data | A data constructor |
| ExternData | A data type foreign import |
| TypeSynonym | A type synonym |
| DataAlias ModuleName ProperName | An alias for a type in another module, introduced using an import declaration |
| LocalTypeVariable | A local type name introduced using a forall quantifier |
Instances
data Environment Source
The Environment defines all values and types which are currently in scope:
Constructors
| Environment | |
Fields
| |
Instances
emptyEnvironment :: EnvironmentSource
An empty environment with no values and no types defined
bindNames :: MonadState CheckState m => Map (ModuleName, Ident) (Type, NameKind) -> m a -> m aSource
Temporarily bind a collection of names to values
bindTypes :: MonadState CheckState m => Map (ModuleName, ProperName) (Kind, TypeDeclarationKind) -> m a -> m aSource
Temporarily bind a collection of names to types
withTypeClassDictionaries :: MonadState CheckState m => [TypeClassDictionaryInScope] -> m a -> m aSource
Temporarily make a collection of type class dictionaries available
getTypeClassDictionaries :: (Functor m, MonadState CheckState m) => m [TypeClassDictionaryInScope]Source
Get the currently available list of type class dictionaries
bindLocalVariables :: (Functor m, MonadState CheckState m) => ModuleName -> [(Ident, Type)] -> m a -> m aSource
Temporarily bind a collection of names to local variables
bindLocalTypeVariables :: (Functor m, MonadState CheckState m) => ModuleName -> [(ProperName, Kind)] -> m a -> m aSource
Temporarily bind a collection of names to local type variables
lookupVariable :: (Functor m, MonadState CheckState m, MonadError String m) => ModuleName -> Qualified Ident -> m TypeSource
Lookup the type of a value by name in the Environment
lookupTypeVariable :: (Functor m, MonadState CheckState m, MonadError String m) => ModuleName -> Qualified ProperName -> m KindSource
Lookup the kind of a type by name in the Environment
canonicalize :: ModuleName -> Environment -> Qualified Ident -> (ModuleName, Ident)Source
Canonicalize an identifier by resolving any aliases introduced by module imports
canonicalizeType :: ModuleName -> Environment -> Qualified ProperName -> (ModuleName, ProperName)Source
Canonicalize a type variable by resolving any aliases introduced by module imports
data CheckState Source
State required for type checking:
Constructors
| CheckState | |
Fields
| |
Instances
The type checking monad, which provides the state of the type checker, and error reporting capabilities
getEnv :: (Functor m, MonadState CheckState m) => m EnvironmentSource
Get the current Environment
putEnv :: MonadState CheckState m => Environment -> m ()Source
modifyEnv :: MonadState CheckState m => (Environment -> Environment) -> m ()Source
Modify the Environment
runCheck :: Check a -> Either String (a, Environment)Source
Run a computation in the Check monad, failing with an error, or succeeding with a return value and the final Environment.
guardWith :: MonadError e m => e -> Bool -> m ()Source
Make an assertion, failing with an error message
rethrow :: MonadError e m => (e -> e) -> m a -> m aSource
Rethrow an error with a more detailed error message in the case of failure
freshDictionaryName :: Check IntSource
Generate new type class dictionary name
newtype Substitution Source
A substitution maintains a mapping from unification variables to their values, ensuring that the type of a unification variable matches the type of its value.
Constructors
| Substitution | |
Fields
| |
Instances
data SubstState Source
State for the substitution monad, which contains the current substitution
Constructors
| SubstState | |
Fields | |
newtype SubstContext Source
Configuration for the substitution monad, constaining the current module
Constructors
| SubstContext | |
Fields | |
Instances
The substitution monad, which provides the means to unify values to generate a substitution, in addition to
the actions supported by the type checking monad Check.
Constructors
| Subst | |
Fields
| |
liftCheck :: Check a -> Subst aSource
Lift a computation in the Check monad into the substitution monad.
getSubstState :: Subst SubstStateSource
Get the current substitution monad state
runSubst :: SubstContext -> Subst a -> Check (a, Substitution)Source
Run a computation in the substitution monad, generating a return value and the final substitution.
substituteWith :: Typeable t => (Unknown t -> t) -> SubstitutionSource
Generate a substitution from a substitution function for a single type
substituteOne :: Unifiable t => Unknown t -> t -> SubstitutionSource
Substitute a single unification variable
replace :: Unifiable t => Unknown t -> t -> Subst ()Source
Replace a unification variable with the specified value in the current substitution
class (Typeable t, Data t, Show t) => Unifiable t whereSource
Identifies types which support unification
occursCheck :: Unifiable t => Unknown s -> t -> Subst ()Source
Perform the occurs check, to make sure a unification variable does not occur inside a value
qualifyAllUnqualifiedNames :: Data d => ModuleName -> Environment -> d -> dSource
Replace any unqualified names in a type wit their qualified versionss