Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- plugin :: Plugin
- data DeriveAll
- = DeriveAll
- | DeriveAllBut {
- _ignoreList :: [String]
- | DeriveAll' {
- _forcedMode :: OverlapMode
- _ignoreList :: [String]
- type family DeriveContext (t :: Type) :: Constraint
- newtype ToInstance = ToInstance {}
- data OverlapMode
Documentation
To use the plugin, add
{-# OPTIONS_GHC -fplugin Data.Constraint.Deriving #-}
to the header of your file.
For debugging, add a plugin option dump-instances
{-# OPTIONS_GHC -fplugin-opt Data.Constraint.Deriving:dump-instances #-}
to the header of your file; it will print all instances declared in the module (hand-written and auto-generated).
DeriveAll pass
A marker to tell the core plugin to derive all visible class instances for a given newtype.
The deriving logic is to simply re-use existing instance dictionaries by type-casting.
DeriveAll | Same as |
DeriveAllBut | Specify a list of class names to ignore |
| |
DeriveAll' | Specify an overlap mode and a list of class names to ignore |
|
Instances
Eq DeriveAll Source # | |
Data DeriveAll Source # | |
Defined in Data.Constraint.Deriving.DeriveAll gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> DeriveAll -> c DeriveAll # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c DeriveAll # toConstr :: DeriveAll -> Constr # dataTypeOf :: DeriveAll -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c DeriveAll) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c DeriveAll) # gmapT :: (forall b. Data b => b -> b) -> DeriveAll -> DeriveAll # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> DeriveAll -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> DeriveAll -> r # gmapQ :: (forall d. Data d => d -> u) -> DeriveAll -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> DeriveAll -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> DeriveAll -> m DeriveAll # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> DeriveAll -> m DeriveAll # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> DeriveAll -> m DeriveAll # | |
Read DeriveAll Source # | |
Show DeriveAll Source # | |
type family DeriveContext (t :: Type) :: Constraint Source #
ToInstance pass
newtype ToInstance Source #
A marker to tell the core plugin to convert a top-level Dict
binding into
an instance declaration.
Example:
type family FooFam a where FooFam Int = Int FooFam a = Double data FooSing a where FooInt :: FooSing Int FooNoInt :: FooSing a class FooClass a where fooSing :: FooSing a newtype Bar a = Bar (FooFam a) {-# ANN fooNum (ToInstance NoOverlap) #-} fooNum :: forall a . Dict (Num (Bar a)) fooNum = mapDict (unsafeDerive Bar) $ case fooSing @a of FooInt -> Dict FooNoInt -> Dict
Note:
fooNum
should be exported by the module (otherwise, it may be optimized-out before the core plugin pass);- Constraints of the function become constraints of the new instance;
- The argument of
Dict
must be a single class (no constraint tuples or equality constraints); - The instance is created in a core-to-core pass, so it does not exist for the type checker in the current module.
Instances
data OverlapMode Source #
Define the behavior for the instance selection.
Mirrors OverlapMode
, but does not have a SourceText
field.
NoOverlap | This instance must not overlap another |
Overlappable | Silently ignore this instance if you find a more specific one that matches the constraint you are trying to resolve |
Overlapping | Silently ignore any more general instances that may be used to solve the constraint. |
Overlaps | Equivalent to having both |
Incoherent | Behave like Overlappable and Overlapping, and in addition pick an an arbitrary one if there are multiple matching candidates, and don't worry about later instantiation |