Portability portable Stability experimental Maintainer dan.doel@gmail.com
Description
An implementation of the cofree comonad of a functor, used in histomorphisms and chronomorphisms in Control.Recursion. The cofree comonad can also be seen as a stream parameterized by a functor that controls its branching factor.
Synopsis
data Cofree h a = Cofree {
 unCofree :: (a, h (Cofree h a))
}
headCofree :: Cofree h a -> a
tailCofree :: Cofree h a -> h (Cofree h a)
anaCofree :: Functor h => (a -> b) -> (a -> h a) -> a -> Cofree h b
cofreeToList :: Cofree Maybe a -> [a]
distribCofree :: (Functor h, Functor f) => (forall a. f (h a) -> h (f a)) -> forall a. f (Cofree h a) -> Cofree h (f a)
Documentation
 data Cofree h a Source

The cofree comonad of a functor h (also known as an H-branching stream). Various comonads are a special instance of the cofree comonad:

• Cofree Identity is an infinite stream
• Cofree Maybe is a non-empty stream
• Cofree [] is a rose tree

formally:

``` Cofree H A = nu X. A * HX
```
Constructors
Cofree
 unCofree :: (a, h (Cofree h a))
Instances
 Functor h => Functor (Cofree h) Functor h => Comonad (Cofree h)
 headCofree :: Cofree h a -> a Source
 tailCofree :: Cofree h a -> h (Cofree h a) Source
 anaCofree :: Functor h => (a -> b) -> (a -> h a) -> a -> Cofree h b Source
anamorphism for building a cofree comonad from a seed
 cofreeToList :: Cofree Maybe a -> [a] Source
Converts a value of the cofree comonad over Maybe into a non-empty list.
 distribCofree :: (Functor h, Functor f) => (forall a. f (h a) -> h (f a)) -> forall a. f (Cofree h a) -> Cofree h (f a) Source
Lifts a distributive law of f over h to a distributive law of f over Cofree h.