License | BSD-style (see the file LICENSE) |
---|---|

Maintainer | sjoerd@w3future.com |

Stability | experimental |

Portability | non-portable |

Safe Haskell | None |

Language | Haskell98 |

This module is for writing generic functions on algebraic data types
of kind `*`

. These data types must be an instance of the `Generic`

type
class, which can be derived.

- create :: (ADT t, Constraints t c) => for c -> (forall s. c s => [s]) -> [t]
- createA :: (ADT t, Constraints t c, Applicative f) => for c -> (forall s. c s => [f s]) -> [f t]
- ctorIndex :: ADT t => t -> Int
- gmap :: (ADT t, Constraints t c) => for c -> (forall s. c s => s -> s) -> t -> t
- gfoldMap :: (ADT t, Constraints t c, Monoid m) => for c -> (forall s. c s => s -> m) -> t -> m
- gtraverse :: (ADT t, Constraints t c, Applicative f) => for c -> (forall s. c s => s -> f s) -> t -> f t
- gzipWith :: (ADT t, Constraints t c) => for c -> (forall s. c s => s -> s -> Maybe s) -> t -> t -> Maybe t
- mzipWith :: (ADT t, Constraints t c, Monoid m) => for c -> (forall s. c s => s -> s -> m) -> t -> t -> m
- zipWithA :: (ADT t, Constraints t c, Applicative f) => for c -> (forall s. c s => s -> s -> Maybe (f s)) -> t -> t -> Maybe (f t)
- consume :: (ADT t, Constraints t c, Decidable f) => for c -> (forall s. c s => f s) -> f t
- op0 :: (ADTRecord t, Constraints t c) => for c -> (forall s. c s => s) -> t
- op1 :: (ADTRecord t, Constraints t c) => for c -> (forall s. c s => s -> s) -> t -> t
- op2 :: (ADTRecord t, Constraints t c) => for c -> (forall s. c s => s -> s -> s) -> t -> t -> t
- class Profunctor p => GenericProfunctor p where
- generic :: (ADT t, Constraints t c, GenericProfunctor p) => for c -> (forall s. c s => p s s) -> p t t
- type ADT t = (Generic t, ADT' (Rep t))
- type ADTRecord t = (ADT t, 1 ~ CtorCount t)
- type ADTNonEmpty t = (ADT t, 1 <= CtorCount t)
- type CtorCount t = CtorCount' (Rep t)
- type Constraints t c = Constraints' (Rep t) c
- data For c = For

# Producing values

create :: (ADT t, Constraints t c) => for c -> (forall s. c s => [s]) -> [t] Source #

createA :: (ADT t, Constraints t c, Applicative f) => for c -> (forall s. c s => [f s]) -> [f t] Source #

# Traversing values

gmap :: (ADT t, Constraints t c) => for c -> (forall s. c s => s -> s) -> t -> t Source #

Map over a structure, updating each component.

gfoldMap :: (ADT t, Constraints t c, Monoid m) => for c -> (forall s. c s => s -> m) -> t -> m Source #

gtraverse :: (ADT t, Constraints t c, Applicative f) => for c -> (forall s. c s => s -> f s) -> t -> f t Source #

Map each component of a structure to an action, evaluate these actions from left to right, and collect the results.

# Combining values

gzipWith :: (ADT t, Constraints t c) => for c -> (forall s. c s => s -> s -> Maybe s) -> t -> t -> Maybe t Source #

Combine two values by combining each component of the structures with the given function.
Returns `Nothing`

if the constructors don't match.

mzipWith :: (ADT t, Constraints t c, Monoid m) => for c -> (forall s. c s => s -> s -> m) -> t -> t -> m Source #

zipWithA :: (ADT t, Constraints t c, Applicative f) => for c -> (forall s. c s => s -> s -> Maybe (f s)) -> t -> t -> Maybe (f t) Source #

Combine two values by combining each component of the structures with the given function, under an applicative effect.
Returns `Nothing`

if the constructors don't match.

# Consuming values

consume :: (ADT t, Constraints t c, Decidable f) => for c -> (forall s. c s => f s) -> f t Source #

Generate ways to consume values of type `t`

. This is the contravariant version of `createA`

.

# Single constructor functions

op0 :: (ADTRecord t, Constraints t c) => for c -> (forall s. c s => s) -> t Source #

op1 :: (ADTRecord t, Constraints t c) => for c -> (forall s. c s => s -> s) -> t -> t Source #

op2 :: (ADTRecord t, Constraints t c) => for c -> (forall s. c s => s -> s -> s) -> t -> t -> t Source #

# Generic programming with profunctors

class Profunctor p => GenericProfunctor p where Source #

zero :: p (V1 a) (V1 a) Source #

unit :: p (U1 a) (U1 a) Source #

plus :: p (f a) (f' a) -> p (g a) (g' a) -> p ((f :+: g) a) ((f' :+: g') a) Source #

mult :: p (f a) (f' a) -> p (g a) (g' a) -> p ((f :*: g) a) ((f' :*: g') a) Source #

Applicative f => GenericProfunctor (Star f) Source # | |

generic :: (ADT t, Constraints t c, GenericProfunctor p) => for c -> (forall s. c s => p s s) -> p t t Source #

All the above functions have been implemented using this single function,
using different `profunctor`

s.

# Types

type ADTNonEmpty t = (ADT t, 1 <= CtorCount t) Source #

`ADTNonEmpty`

is a constraint type synonym. An instance is an `ADT`

with *at least* one constructor.

type CtorCount t = CtorCount' (Rep t) Source #

type Constraints t c = Constraints' (Rep t) c 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`

.