Safe Haskell | None |
---|---|
Language | Haskell2010 |
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?)
- type InstMap = Map (E Pred) [DecStatus InstanceDec]
- class (DsMonad m, MonadStates InstMap m, MonadStates ExpandMap m, MonadStates String m) => ContextM m
- data DecStatus a
- = Declared {
- instanceDec :: a
- | Undeclared {
- instanceDec :: a
- = Declared {
- reifyInstancesWithContext :: forall m. ContextM m => Name -> [Type] -> m [InstanceDec]
- tellInstance :: ContextM m => Dec -> m ()
- tellUndeclared :: (MonadWriter [Dec] m, MonadStates InstMap m) => m ()
- noInstance :: forall m. ContextM m => Name -> Name -> m Bool
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.
Did we get this instance from the Q monad or does it still need to be spliced?
Declared | An instance we found in the Q monad |
| |
Undeclared | An instance we inserted via tellInstance |
|
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.