Stability | experimental |
---|---|

Maintainer | ekmett@gmail.com |

Representable endofunctors over the category of Haskell types are isomorphic to the reader monad and so inherit a very large number of properties for free.

- class (Indexable f, Distributive f, Keyed f, Apply f, Applicative f, ZipWithKey f) => Representable f where
- repLens :: Representable f => Lens a b -> Lens (f a) (f b)
- fmapRep :: Representable f => (a -> b) -> f a -> f b
- distributeRep :: (Representable f, Functor w) => w (f a) -> f (w a)
- mapWithKeyRep :: Representable f => (Key f -> a -> b) -> f a -> f b
- apRep :: Representable f => f (a -> b) -> f a -> f b
- pureRep :: Representable f => a -> f a
- bindRep :: Representable f => f a -> (a -> f b) -> f b
- bindWithKeyRep :: Representable f => f a -> (Key f -> a -> f b) -> f b
- zipWithRep :: Representable f => (a -> b -> c) -> f a -> f b -> f c
- zipWithKeyRep :: Representable f => (Key f -> a -> b -> c) -> f a -> f b -> f c
- askRep :: Representable f => f (Key f)
- localRep :: Representable f => (Key f -> Key f) -> f a -> f a
- duplicateRep :: (Representable f, Semigroup (Key f)) => f a -> f (f a)
- extendRep :: (Representable f, Semigroup (Key f)) => (f a -> b) -> f a -> f b
- extractRep :: (Indexable f, Monoid (Key f)) => f a -> a

# Representable Functors

class (Indexable f, Distributive f, Keyed f, Apply f, Applicative f, ZipWithKey f) => Representable f whereSource

A `Functor`

`f`

is `Representable`

if `tabulate`

and `index`

witness an isomorphism to `(->) x`

.

tabulate . index = id index . tabulate = id tabulate . return f = return f

Representable Identity | |

Representable ((->) e) | |

Representable m => Representable (IdentityT m) | |

Representable f => Representable (Cofree f) | |

Representable w => Representable (TracedT s w) | |

Representable m => Representable (ReaderT e m) | |

(Representable f, Representable g) => Representable (Compose f g) | |

(Representable f, Representable g) => Representable (Product f g) | |

(Representable f, Representable m) => Representable (ReaderT f m) |

## Representable Lenses

repLens :: Representable f => Lens a b -> Lens (f a) (f b)Source

We extend lens across a representable functor, due to the preservation of limits.

# Default definitions

## Functor

fmapRep :: Representable f => (a -> b) -> f a -> f bSource

## Distributive

distributeRep :: (Representable f, Functor w) => w (f a) -> f (w a)Source

## Keyed

mapWithKeyRep :: Representable f => (Key f -> a -> b) -> f a -> f bSource

## Apply/Applicative

apRep :: Representable f => f (a -> b) -> f a -> f bSource

pureRep :: Representable f => a -> f aSource

## Bind/Monad

bindRep :: Representable f => f a -> (a -> f b) -> f bSource

bindWithKeyRep :: Representable f => f a -> (Key f -> a -> f b) -> f bSource

## Zip/ZipWithKey

zipWithRep :: Representable f => (a -> b -> c) -> f a -> f b -> f cSource

zipWithKeyRep :: Representable f => (Key f -> a -> b -> c) -> f a -> f b -> f cSource

## MonadReader

askRep :: Representable f => f (Key f)Source

localRep :: Representable f => (Key f -> Key f) -> f a -> f aSource

## Extend

duplicateRep :: (Representable f, Semigroup (Key f)) => f a -> f (f a)Source

extendRep :: (Representable f, Semigroup (Key f)) => (f a -> b) -> f a -> f bSource

## Comonad

extractRep :: (Indexable f, Monoid (Key f)) => f a -> aSource