th-context-0.24: 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

class (DsMonad m, MonadStates InstMap m, MonadStates ExpandMap m, MonadStates String m) => ContextM m Source #

Combine the DsMonad (desugaring), which includes the Q monad, and state to record declared instances, type expansions, and a string for debugging messages.

Instances

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

Undeclared

An instance we inserted via tellInstance

Fields

Instances

Show a => Show (DecStatus a) Source # 
Ppr a => Ppr (DecStatus a) Source # 

Methods

ppr :: DecStatus a -> Doc #

ppr_list :: [DecStatus a] -> Doc #

reifyInstancesWithContext :: forall m. ContextM 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 :: ContextM 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.

noInstance :: forall m. ContextM m => Name -> Name -> m Bool Source #