| License | BSD-style (see the file LICENSE) |
|---|---|
| Maintainer | sjoerd@w3future.com |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | Trustworthy |
| Language | Haskell98 |
Generics.OneLiner.Binary
Contents
Description
These generic functions allow changing the types of the constant leaves. They require type classes with 2 parameters, the first for the input type and the second for the output type.
All functions without postfix are for instances of Generic, and functions
with postfix 1 are for instances of Generic1 (with kind * -> *) which
get an extra argument to specify how to deal with the parameter.
Functions with postfix 01 are also for Generic1 but they get yet another
argument that, like the Generic functions, allows handling of constant leaves.
- gmap :: forall c t t'. (ADT t t', Constraints t t' c) => (forall s s'. c s s' => s -> s') -> t -> t'
- gtraverse :: forall c t t' f. (ADT t t', Constraints t t' c, Applicative f) => (forall s s'. c s s' => s -> f s') -> t -> f t'
- gmap1 :: forall c t t' a b. (ADT1 t t', Constraints1 t t' c) => (forall d e s s'. c s s' => (d -> e) -> s d -> s' e) -> (a -> b) -> t a -> t' b
- gtraverse1 :: forall c t t' f a b. (ADT1 t t', Constraints1 t t' c, Applicative f) => (forall d e s s'. c s s' => (d -> f e) -> s d -> f (s' e)) -> (a -> f b) -> t a -> f (t' b)
- zipWithA :: forall c t t' f. (ADT t t', Constraints t t' c, Alternative f) => (forall s s'. c s s' => s -> s -> f s') -> t -> t -> f t'
- zipWithA1 :: forall c t t' f a b. (ADT1 t t', Constraints1 t t' c, Alternative f) => (forall d e s s'. c s s' => (d -> d -> f e) -> s d -> s d -> f (s' e)) -> (a -> a -> f b) -> t a -> t a -> f (t' b)
- unaryOp :: forall c t t'. (ADTRecord t t', Constraints t t' c) => (forall s s'. c s s' => s -> s') -> t -> t'
- binaryOp :: forall c t t'. (ADTRecord t t', Constraints t t' c) => (forall s s'. c s s' => s -> s -> s') -> t -> t -> t'
- algebra :: forall c t t' f. (ADTRecord t t', Constraints t t' c, Functor f) => (forall s s'. c s s' => f s -> s') -> f t -> t'
- dialgebra :: forall c t t' f g. (ADTRecord t t', Constraints t t' c, Functor f, Applicative g) => (forall s s'. c s s' => f s -> g s') -> f t -> g t'
- gcotraverse1 :: forall c t t' f a b. (ADTRecord1 t t', Constraints1 t t' c, Functor f) => (forall d e s s'. c s s' => (f d -> e) -> f (s d) -> s' e) -> (f a -> b) -> f (t a) -> t' b
- record :: forall c p t t'. (ADTRecord t t', Constraints t t' c, GenericRecordProfunctor p) => (forall s s'. c s s' => p s s') -> p t t'
- nonEmpty :: forall c p t t'. (ADTNonEmpty t t', Constraints t t' c, GenericNonEmptyProfunctor p) => (forall s s'. c s s' => p s s') -> p t t'
- generic :: forall c p t t'. (ADT t t', Constraints t t' c, GenericProfunctor p) => (forall s s'. c s s' => p s s') -> p t t'
- record1 :: forall c p t t' a b. (ADTRecord1 t t', Constraints1 t t' c, GenericRecordProfunctor p) => (forall d e s s'. c s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b)
- nonEmpty1 :: forall c p t t' a b. (ADTNonEmpty1 t t', Constraints1 t t' c, GenericNonEmptyProfunctor p) => (forall d e s s'. c s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b)
- generic1 :: forall c p t t' a b. (ADT1 t t', Constraints1 t t' c, GenericProfunctor p) => (forall d e s s'. c s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b)
- record01 :: forall c0 c1 p t t' a b. (ADTRecord1 t t', Constraints01 t t' c0 c1, GenericRecordProfunctor p) => (forall s s'. c0 s s' => p s s') -> (forall d e s s'. c1 s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b)
- nonEmpty01 :: forall c0 c1 p t t' a b. (ADTNonEmpty1 t t', Constraints01 t t' c0 c1, GenericNonEmptyProfunctor p) => (forall s s'. c0 s s' => p s s') -> (forall d e s s'. c1 s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b)
- generic01 :: forall c0 c1 p t t' a b. (ADT1 t t', Constraints01 t t' c0 c1, GenericProfunctor p) => (forall s s'. c0 s s' => p s s') -> (forall d e s s'. c1 s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b)
- class (Profunctor p, GenericUnitProfunctor p, GenericProductProfunctor p) => GenericRecordProfunctor p
- class (GenericRecordProfunctor p, GenericSumProfunctor p) => GenericNonEmptyProfunctor p
- class (GenericNonEmptyProfunctor p, GenericEmptyProfunctor p) => GenericProfunctor p
- class Profunctor p => GenericUnitProfunctor p where
- class Profunctor p => GenericProductProfunctor p where
- class Profunctor p => GenericSumProfunctor p where
- class Profunctor p => GenericEmptyProfunctor p where
- type ADT t t' = (Generic t, Generic t', ADT' (Rep t) (Rep t'), Constraints t t' AnyType)
- type ADTNonEmpty t t' = (Generic t, Generic t', ADTNonEmpty' (Rep t) (Rep t'), Constraints t t' AnyType)
- type ADTRecord t t' = (Generic t, Generic t', ADTRecord' (Rep t) (Rep t'), Constraints t t' AnyType)
- type Constraints t t' c = Constraints' (Rep t) (Rep t') c AnyType
- type ADT1 t t' = (Generic1 t, Generic1 t', ADT1' (Rep1 t) (Rep1 t'), Constraints1 t t' AnyType)
- type ADTNonEmpty1 t t' = (Generic1 t, Generic1 t', ADTNonEmpty1' (Rep1 t) (Rep1 t'), Constraints1 t t' AnyType)
- type ADTRecord1 t t' = (Generic1 t, Generic1 t', ADTRecord1' (Rep1 t) (Rep1 t'), Constraints1 t t' AnyType)
- type Constraints1 t t' c = Constraints' (Rep1 t) (Rep1 t') AnyType c
- type Constraints01 t t' c0 c1 = Constraints' (Rep1 t) (Rep1 t') c0 c1
- class FunConstraints c t
- type family FunResult t where ...
- class AnyType a b
Traversing values
gmap :: forall c t t'. (ADT t t', Constraints t t' c) => (forall s s'. c s s' => s -> s') -> t -> t' Source #
gtraverse :: forall c t t' f. (ADT t t', Constraints t t' c, Applicative f) => (forall s s'. c s s' => s -> f s') -> t -> f t' Source #
gmap1 :: forall c t t' a b. (ADT1 t t', Constraints1 t t' c) => (forall d e s s'. c s s' => (d -> e) -> s d -> s' e) -> (a -> b) -> t a -> t' b Source #
gtraverse1 :: forall c t t' f a b. (ADT1 t t', Constraints1 t t' c, Applicative f) => (forall d e s s'. c s s' => (d -> f e) -> s d -> f (s' e)) -> (a -> f b) -> t a -> f (t' b) Source #
gtraverse1 is generic1 specialized to Star.
Combining values
zipWithA :: forall c t t' f. (ADT t t', Constraints t t' c, Alternative f) => (forall s s'. c s s' => s -> s -> f s') -> t -> t -> f t' Source #
zipWithA1 :: forall c t t' f a b. (ADT1 t t', Constraints1 t t' c, Alternative f) => (forall d e s s'. c s s' => (d -> d -> f e) -> s d -> s d -> f (s' e)) -> (a -> a -> f b) -> t a -> t a -> f (t' b) Source #
Functions for records
These functions only work for single constructor data types.
unaryOp :: forall c t t'. (ADTRecord t t', Constraints t t' c) => (forall s s'. c s s' => s -> s') -> t -> t' Source #
binaryOp :: forall c t t'. (ADTRecord t t', Constraints t t' c) => (forall s s'. c s s' => s -> s -> s') -> t -> t -> t' Source #
algebra :: forall c t t' f. (ADTRecord t t', Constraints t t' c, Functor f) => (forall s s'. c s s' => f s -> s') -> f t -> t' Source #
dialgebra :: forall c t t' f g. (ADTRecord t t', Constraints t t' c, Functor f, Applicative g) => (forall s s'. c s s' => f s -> g s') -> f t -> g t' Source #
gcotraverse1 :: forall c t t' f a b. (ADTRecord1 t t', Constraints1 t t' c, Functor f) => (forall d e s s'. c s s' => (f d -> e) -> f (s d) -> s' e) -> (f a -> b) -> f (t a) -> t' b Source #
gcotraverse1 is record1 specialized to Costar.
Generic programming with profunctors
All the above functions have been implemented using these functions,
using different profunctors.
record :: forall c p t t'. (ADTRecord t t', Constraints t t' c, GenericRecordProfunctor p) => (forall s s'. c s s' => p s s') -> p t t' Source #
nonEmpty :: forall c p t t'. (ADTNonEmpty t t', Constraints t t' c, GenericNonEmptyProfunctor p) => (forall s s'. c s s' => p s s') -> p t t' Source #
generic :: forall c p t t'. (ADT t t', Constraints t t' c, GenericProfunctor p) => (forall s s'. c s s' => p s s') -> p t t' Source #
record1 :: forall c p t t' a b. (ADTRecord1 t t', Constraints1 t t' c, GenericRecordProfunctor p) => (forall d e s s'. c s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b) Source #
nonEmpty1 :: forall c p t t' a b. (ADTNonEmpty1 t t', Constraints1 t t' c, GenericNonEmptyProfunctor p) => (forall d e s s'. c s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b) Source #
generic1 :: forall c p t t' a b. (ADT1 t t', Constraints1 t t' c, GenericProfunctor p) => (forall d e s s'. c s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b) Source #
record01 :: forall c0 c1 p t t' a b. (ADTRecord1 t t', Constraints01 t t' c0 c1, GenericRecordProfunctor p) => (forall s s'. c0 s s' => p s s') -> (forall d e s s'. c1 s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b) Source #
nonEmpty01 :: forall c0 c1 p t t' a b. (ADTNonEmpty1 t t', Constraints01 t t' c0 c1, GenericNonEmptyProfunctor p) => (forall s s'. c0 s s' => p s s') -> (forall d e s s'. c1 s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b) Source #
generic01 :: forall c0 c1 p t t' a b. (ADT1 t t', Constraints01 t t' c0 c1, GenericProfunctor p) => (forall s s'. c0 s s' => p s s') -> (forall d e s s'. c1 s s' => p d e -> p (s d) (s' e)) -> p a b -> p (t a) (t' b) Source #
Classes
class (Profunctor p, GenericUnitProfunctor p, GenericProductProfunctor p) => GenericRecordProfunctor p Source #
A generic function using a GenericRecordProfunctor works on any data type
with exactly one constructor, a.k.a. records,
with multiple fields (mult) or no fields (unit).
GenericRecordProfunctor is similar to ProductProfuctor from the
product-profunctor package, but using types from GHC.Generics.
Instances
class (GenericRecordProfunctor p, GenericSumProfunctor p) => GenericNonEmptyProfunctor p Source #
A generic function using a GenericNonEmptyProfunctor works on any data
type with at least one constructor.
Instances
class (GenericNonEmptyProfunctor p, GenericEmptyProfunctor p) => GenericProfunctor p Source #
A generic function using a GenericProfunctor works on any
algebraic data type, including those with no constructors and constants.
Instances
class Profunctor p => GenericUnitProfunctor p where Source #
Minimal complete definition
Instances
| Applicative f => GenericUnitProfunctor (Star f) Source # | |
| Functor f => GenericUnitProfunctor (Costar f) Source # | |
| GenericUnitProfunctor (Tagged *) Source # | |
| Applicative f => GenericUnitProfunctor (Zip f) Source # | |
| GenericUnitProfunctor (Ctor *) Source # | |
| GenericUnitProfunctor ((->) LiftedRep LiftedRep) Source # | |
| Applicative f => GenericUnitProfunctor (Joker * * f) Source # | |
| Divisible f => GenericUnitProfunctor (Clown * * f) Source # | |
| (GenericUnitProfunctor p, GenericUnitProfunctor q) => GenericUnitProfunctor (Product * * p q) Source # | |
| (Applicative f, GenericUnitProfunctor p) => GenericUnitProfunctor (Tannen * * * f p) Source # | |
| (Functor f, Applicative g, Profunctor p, GenericUnitProfunctor p) => GenericUnitProfunctor (Biff * * * * p f g) Source # | |
class Profunctor p => GenericProductProfunctor p where Source #
Minimal complete definition
Instances
| Applicative f => GenericProductProfunctor (Star f) Source # | |
| Functor f => GenericProductProfunctor (Costar f) Source # | |
| GenericProductProfunctor (Tagged *) Source # | |
| Applicative f => GenericProductProfunctor (Zip f) Source # | |
| GenericProductProfunctor (Ctor *) Source # | |
| GenericProductProfunctor ((->) LiftedRep LiftedRep) Source # | |
| Applicative f => GenericProductProfunctor (Joker * * f) Source # | |
| Divisible f => GenericProductProfunctor (Clown * * f) Source # | |
| (GenericProductProfunctor p, GenericProductProfunctor q) => GenericProductProfunctor (Product * * p q) Source # | |
| (Applicative f, GenericProductProfunctor p) => GenericProductProfunctor (Tannen * * * f p) Source # | |
| (Functor f, Applicative g, Profunctor p, GenericProductProfunctor p) => GenericProductProfunctor (Biff * * * * p f g) Source # | |
class Profunctor p => GenericSumProfunctor p where Source #
Minimal complete definition
Instances
| Applicative f => GenericSumProfunctor (Star f) Source # | |
| Alternative f => GenericSumProfunctor (Zip f) Source # | |
| GenericSumProfunctor (Ctor *) Source # | |
| GenericSumProfunctor ((->) LiftedRep LiftedRep) Source # | |
| Alternative f => GenericSumProfunctor (Joker * * f) Source # | |
| Decidable f => GenericSumProfunctor (Clown * * f) Source # | |
| (GenericSumProfunctor p, GenericSumProfunctor q) => GenericSumProfunctor (Product * * p q) Source # | |
| (Applicative f, GenericSumProfunctor p) => GenericSumProfunctor (Tannen * * * f p) Source # | |
class Profunctor p => GenericEmptyProfunctor p where Source #
Instances
| Applicative f => GenericEmptyProfunctor (Star f) Source # | |
| Alternative f => GenericEmptyProfunctor (Zip f) Source # | |
| GenericEmptyProfunctor (Ctor *) Source # | |
| GenericEmptyProfunctor ((->) LiftedRep LiftedRep) Source # | |
| Alternative f => GenericEmptyProfunctor (Joker * * f) Source # | |
| Decidable f => GenericEmptyProfunctor (Clown * * f) Source # | |
| (GenericEmptyProfunctor p, GenericEmptyProfunctor q) => GenericEmptyProfunctor (Product * * p q) Source # | |
| (Applicative f, GenericEmptyProfunctor p) => GenericEmptyProfunctor (Tannen * * * f p) Source # | |
Types
type ADTNonEmpty t t' = (Generic t, Generic t', ADTNonEmpty' (Rep t) (Rep t'), Constraints t t' AnyType) Source #
ADTNonEmpty is a constraint type synonym. An instance is an ADT with *at least* one constructor.
type ADTRecord t t' = (Generic t, Generic t', ADTRecord' (Rep t) (Rep t'), Constraints t t' AnyType) Source #
type Constraints t t' c = Constraints' (Rep t) (Rep t') c AnyType Source #
Constraints is a constraint type synonym, containing the constraint
requirements for an instance for t of class c.
It requires an instance of class c for each component of t.
type ADT1 t t' = (Generic1 t, Generic1 t', ADT1' (Rep1 t) (Rep1 t'), Constraints1 t t' AnyType) Source #
type ADTNonEmpty1 t t' = (Generic1 t, Generic1 t', ADTNonEmpty1' (Rep1 t) (Rep1 t'), Constraints1 t t' AnyType) Source #
type ADTRecord1 t t' = (Generic1 t, Generic1 t', ADTRecord1' (Rep1 t) (Rep1 t'), Constraints1 t t' AnyType) Source #
type Constraints1 t t' c = Constraints' (Rep1 t) (Rep1 t') AnyType c Source #
type Constraints01 t t' c0 c1 = Constraints' (Rep1 t) (Rep1 t') c0 c1 Source #
class FunConstraints c t Source #
Automatically apply a lifted function to a polymorphic argument as many times as possible.
A constraint `FunConstraint c t` is equivalent to the conjunction of
constraints `c s` for every argument type of t.
If r is not a function type:
c a :- FunConstraints c (a -> r) (c a, c b) :- FunConstraints c (a -> b -> r) (c a, c b, c d) :- FunConstraints c (a -> b -> d -> r)
Minimal complete definition
Instances
| (~) * (FunResult r) r => FunConstraints c r Source # | |
| (c a, FunConstraints c b) => FunConstraints c (a -> b) Source # | |