th-context-0.22: Test instance context

Safe HaskellNone
LanguageHaskell2010

Language.Haskell.TH.Context

Description

Compute whether any existing instance satisfies some context in a nearly correct fashion. instance A m => B m where ... I say "nearly correct" because there are cases which are not handled exactly the way GHC behaves, which may lead to false (positives? negatives?)

Synopsis

Documentation

data DecStatus a Source

Did we get this instance from the Q monad or does it still need to be spliced?

Constructors

Declared

An instance we found in the Q monad

Fields

instanceDec :: a
 
Undeclared

An instance we inserted via tellInstance

Fields

instanceDec :: a
 

Instances

reifyInstancesWithContext :: forall m. (DsMonad m, MonadStates InstMap m, MonadStates ExpandMap m) => Name -> [Type] -> m [InstanceDec] Source

Like qReifyInstances, looks up all the instances that match the given class name and argument types. Unlike qReifyInstances, only the ones that satisfy all the instance context predicates in the environment are returned. If there is already an instance that satisfies the predicate built from the name and types it is returned. If not, this new predicate is inserted into the state monad InstMap, associated with an empty list of predicates, and the empty list is returned. Later the caller can use tellInstance to associate instances with the predicate.

tellInstance :: (DsMonad m, MonadStates InstMap m, Quasi m, MonadStates ExpandMap m) => Dec -> m () Source

Declare an instance in the state monad, marked Undeclared. After this, the instance predicate (constructed from class name and type parameters) will be considered part of the context for subsequent calls to reifyInstancesWithContext.

tellUndeclared :: (MonadWriter [Dec] m, MonadStates InstMap m) => m () Source

After all the declared and undeclared instances have been added to the instance map using tellInstance, this returns the undeclared instances only, not the ones that were discovered by reifyInstances, and tells them to the writer monad.