| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Constraint.Deriving.ToInstance
Synopsis
- newtype ToInstance = ToInstance {}
- data OverlapMode
- toInstancePass :: CorePluginEnvRef -> CoreToDo
- type CorePluginEnvRef = IORef CorePluginEnv
- initCorePluginEnv :: CoreM (IORef CorePluginEnv)
Documentation
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:
fooNumshould 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
Dictmust 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.
Constructors
| ToInstance | |
Fields | |
Instances
data OverlapMode Source #
Define the behavior for the instance selection.
Mirrors OverlapMode, but does not have a SourceText field.
Constructors
| 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 |
Instances
toInstancePass :: CorePluginEnvRef -> CoreToDo Source #
Run ToInstance plugin pass
type CorePluginEnvRef = IORef CorePluginEnv Source #
Reference to the plugin environment variables.
initCorePluginEnv :: CoreM (IORef CorePluginEnv) Source #
Init the CorePluginM environment and save it to IORef.