-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Test instance context
--
-- Use these functions to decide an a not-quite naive fashion whether an
-- instance already exists that satisfies a given context. This can be
-- used to decide whether an instance needs to be generated, as in
-- th-reify-many. Known limitation: the instances inserted into the
-- InstMap are not fully recognized when computing the context.
@package th-context
@version 0.22
-- | 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?)
module Language.Haskell.TH.Context
type InstMap = Map (E Pred) [DecStatus InstanceDec]
-- | Did we get this instance from the Q monad or does it still need to be
-- spliced?
data DecStatus a
-- | An instance we found in the Q monad
Declared :: a -> DecStatus a
[instanceDec] :: DecStatus a -> a
-- | An instance we inserted via tellInstance
Undeclared :: a -> DecStatus a
[instanceDec] :: DecStatus a -> a
-- | 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.
reifyInstancesWithContext :: (DsMonad m, MonadStates InstMap m, MonadStates ExpandMap m) => Name -> [Type] -> m [InstanceDec]
-- | 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.
tellInstance :: (DsMonad m, MonadStates InstMap m, Quasi m, MonadStates ExpandMap m) => Dec -> m ()
-- | 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.
tellUndeclared :: (MonadWriter [Dec] m, MonadStates InstMap m) => m ()
instance GHC.Show.Show a => GHC.Show.Show (Language.Haskell.TH.Context.DecStatus a)
instance Language.Haskell.TH.Ppr.Ppr a => Language.Haskell.TH.Ppr.Ppr (Language.Haskell.TH.Context.DecStatus a)