| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Barbie.Constraints
Description
Support for operating on Barbie-types with constrained functions.
Consider the following function:
showIt ::Showa =>Maybea ->ConstStringa showIt =Const.show
We would then like to be able to do:
bmapshowIt::FunctorBb => bMaybe-> b (ConstString)
This however doesn't work because of the ( constraint in the
the type of Show a)showIt.
This module adds support to overcome this problem.
- data DictOf c f a where
- PackedDict :: c (f a) => DictOf c f a
- packDict :: c (f a) => DictOf c f a
- requiringDict :: (c (f a) => r) -> DictOf c f a -> r
- class FunctorB b => ConstraintsB b where
- type ConstraintsOf (c :: * -> Constraint) (f :: * -> *) b :: Constraint
- class (ConstraintsB b, ProductB b) => ProofB b where
Proof of instance
data DictOf c f a where Source #
is evidence that there exists an instance
of DictOf c f ac (f a).
Constructors
| PackedDict :: c (f a) => DictOf c f a |
requiringDict :: (c (f a) => r) -> DictOf c f a -> r Source #
Turn a constrained-function into an unconstrained one that uses the packed instance dictionary instead.
Retrieving proofs
class FunctorB b => ConstraintsB b Source #
Instances of this class provide means to talk about constraints,
both at compile-time, using ConstraintsOf and at run-time,
in the form of class instance dictionaries, via adjProof.
A manual definition would look like this:
data T f = A (fInt) (fString) | B (fBool) (fInt) instanceConstraintsBT where typeConstraintsOfc f T = (c (fInt), c (fString), c (fBool)) adjProof t = case t of A x y -> A (Pair(packDictx) (packDicty)) B z w -> B (Pair(packDictz) (packDictw))
There is a default implementation of ConstraintsOf for
Generic types, so in practice one will simply do:
derive instanceGenericT instanceConstraintsBT
Associated Types
type ConstraintsOf (c :: * -> Constraint) (f :: * -> *) b :: Constraint Source #
should contain a constraint ConstraintsOf c f bc (f x)
for each f x occurring in b. E.g.:
ConstraintsOfShowf Barbie = (Show(fString),Show(fInt))
Instances
| ConstraintsB b => ConstraintsB (Barbie b) Source # | |
class (ConstraintsB b, ProductB b) => ProofB b where Source #
Barbie-types with products have a canonical proof of instance.
There is a default bproof implementation for Generic types, so
instances can derived automatically.
Methods
bproof :: ConstraintsOf c f b => b (DictOf c f) Source #
bproof :: (CanDeriveGenericInstance b, ConstraintsOfMatchesGenericDeriv c f b, ConstraintsOf c f b) => b (DictOf c f) Source #