Portability | MPTCs, fundeps |
---|---|

Stability | provisional |

Maintainer | Edward Kmett <ekmett@gmail.com> |

Safe Haskell | Safe-Infered |

Cofree comonads

- data Cofree f a = a :< (f (Cofree f a))
- class (Functor f, Comonad w) => ComonadCofree f w | w -> f where
- unwrap :: w a -> f (w a)

- section :: Comonad f => f a -> Cofree f a
- coiter :: Functor f => (a -> f a) -> a -> Cofree f a
- unfold :: Functor f => (b -> (a, f b)) -> b -> Cofree f a
- extracted :: Functor f => (a -> f a) -> Cofree g a -> f (Cofree g a)
- unwrapped :: Functor f => (g (Cofree g a) -> f (g (Cofree g a))) -> Cofree g a -> f (Cofree g a)
- telescoped :: (Functor f, Functor g) => [(Cofree g a -> f (Cofree g a)) -> g (Cofree g a) -> f (g (Cofree g a))] -> (a -> f a) -> Cofree g a -> f (Cofree g a)

# Documentation

The `Cofree`

`Comonad`

of a functor `f`

.

*Formally*

A `Comonad`

`v`

is a cofree `Comonad`

for `f`

if every comonad homomorphism
another comonad `w`

to `v`

is equivalent to a natural transformation
from `w`

to `f`

.

A `cofree`

functor is right adjoint to a forgetful functor.

Cofree is a functor from the category of functors to the category of comonads
that is right adjoint to the forgetful functor from the category of comonads
to the category of functors that forgets how to `extract`

and
`duplicate`

, leaving you with only a `Functor`

.

In practice, cofree comonads are quite useful for annotating syntax trees, or talking about streams.

A number of common comonads arise directly as cofree comonads.

For instance,

class (Functor f, Comonad w) => ComonadCofree f w | w -> f whereSource

Allows you to peel a layer off a cofree comonad.

ComonadCofree f w => ComonadCofree f (IdentityT w) | |

Functor f => ComonadCofree f (Cofree f) | |

(ComonadCofree f w, Semigroup m, Monoid m) => ComonadCofree f (TracedT m w) | |

ComonadCofree f w => ComonadCofree f (StoreT s w) | |

ComonadCofree f w => ComonadCofree f (EnvT e w) | |

(Functor f, Comonad w) => ComonadCofree f (CofreeT f w) |

# Lenses into cofree comonads

unwrapped :: Functor f => (g (Cofree g a) -> f (g (Cofree g a))) -> Cofree g a -> f (Cofree g a)Source

telescoped :: (Functor f, Functor g) => [(Cofree g a -> f (Cofree g a)) -> g (Cofree g a) -> f (g (Cofree g a))] -> (a -> f a) -> Cofree g a -> f (Cofree g a)Source

Construct a `Lens`

into a

given a list of lenses into the base functor.
`Cofree`

f

For more on lenses see the `lens`

package on hackage.

telescoped :: Functor g => [Rep g] -> Simple Lens (Cofree g a) a