Safe Haskell | None |
---|---|
Language | Haskell2010 |
Poor man's typechecker in Template Haskell. Capable of working with type synonyms, type families, DataKinds, kind polymorphism.
Levity polymorphism is currently not supported. Return kind inference in type families is not supported.
GHC cannot reify roles correctly, so we cannot solve Coercible constraints correctly, so instance resolution was left out.
Synopsis
- type MonadTc m = (Quasi m, MonadState TcScope m)
- data TcScope
- runTc :: Monad m => StateT TcScope m a -> m a
- type TV = Name
- freshUnifTV :: MonadTc m => m TV
- class HasTV a where
- instantiate :: MonadTc m => a -> m a
- instantiating :: MonadTc m => a -> StateT (Map TV TV) m a
- occurrences :: a -> Set TV
- extractKind :: MonadTc m => Type -> m Kind
- unifyTy :: MonadTc m => Type -> Type -> m ()
- unifyTys :: MonadTc m => [Type] -> [Type] -> m ()
- data UnifyResult
- unifyTyResult :: MonadTc m => Type -> Type -> m UnifyResult
- unifyTysResult :: MonadTc m => [Type] -> [Type] -> m UnifyResult
- extractSubst :: MonadTc m => Type -> m [(TV, Type)]
- substZonked :: MonadTc m => Type -> m Type
Documentation
Scope of the typechecker. Includes information about unificational vs rigid (skolem) type variables, and a cache of type information reified from GHC.
runTc :: Monad m => StateT TcScope m a -> m a Source #
Execute a typechecker computation. Unificational variables will not persist
between different runTc
blocks.
freshUnifTV :: MonadTc m => m TV Source #
Make a fresh (unused) unificational type variable. Unification will be able to replace this type variable with a concrete type.
A class for thigns that contain type variables.
instantiate :: MonadTc m => a -> m a Source #
Replace all free variables with fresh unificational type variables.
instantiating :: MonadTc m => a -> StateT (Map TV TV) m a Source #
Replace all free variables with fresh unificational type variables, in a state transformer.
occurrences :: a -> Set TV Source #
Free variables.
extractKind :: MonadTc m => Type -> m Kind Source #
Attempt to compute the kind of a type. GHC doesn't give us complete kind information so this migth be more general than expected.
unifyTy :: MonadTc m => Type -> Type -> m () Source #
Assert that two types are equal, and replace unificational variables as necessary. Throws an error if the two types cannot be shown equal.
unifyTys :: MonadTc m => [Type] -> [Type] -> m () Source #
Assert that two lists of types are equal, replace unificational variables as necessary. Throws an error if two corresponding types could not be shown to be equal, or if lists have different lengths.
data UnifyResult Source #
Result of unification
Apart String | The types are known to be different. (Includes an error message for if the types were expected to be equal). |
Unknown String | The types may be different depending on substitutions of rigid type variables or not-yet-known type family instances. (Includes an error message for if the types were expected to be equal). |
Equal | The types are known to be equal |
Instances
Eq UnifyResult Source # | |
Defined in Language.Haskell.TH.Typecheck (==) :: UnifyResult -> UnifyResult -> Bool # (/=) :: UnifyResult -> UnifyResult -> Bool # | |
Ord UnifyResult Source # | |
Defined in Language.Haskell.TH.Typecheck compare :: UnifyResult -> UnifyResult -> Ordering # (<) :: UnifyResult -> UnifyResult -> Bool # (<=) :: UnifyResult -> UnifyResult -> Bool # (>) :: UnifyResult -> UnifyResult -> Bool # (>=) :: UnifyResult -> UnifyResult -> Bool # max :: UnifyResult -> UnifyResult -> UnifyResult # min :: UnifyResult -> UnifyResult -> UnifyResult # | |
Show UnifyResult Source # | |
Defined in Language.Haskell.TH.Typecheck showsPrec :: Int -> UnifyResult -> ShowS # show :: UnifyResult -> String # showList :: [UnifyResult] -> ShowS # |
unifyTyResult :: MonadTc m => Type -> Type -> m UnifyResult Source #
Attempt unification and return an indication of whether the types were equal or not.
unifyTysResult :: MonadTc m => [Type] -> [Type] -> m UnifyResult Source #