Module

Control.Comonad.Cofree

The cofree comonad for a Functor.

#Cofree

newtype Cofree :: (Type -> Type) -> Type -> Typenewtype Cofree f a

The Cofree Comonad for a functor.

A value of type Cofree f a consists of an f-branching tree, annotated with labels of type a.

The Comonad instance supports redecoration, recomputing labels from the local context.

Instances

#deferCofree

deferCofree :: forall f a. (Unit -> Tuple a (f (Cofree f a))) -> Cofree f a

Lazily creates a value of type Cofree f a from a label and a functor-full of "subtrees".

#mkCofree

mkCofree :: forall f a. a -> f (Cofree f a) -> Cofree f a

Create a value of type Cofree f a from a label and a functor-full of "subtrees".

#(:<)

Operator alias for Control.Comonad.Cofree.mkCofree (right-associative / precedence 5)

#head

head :: forall f a. Cofree f a -> a

Returns the label for a tree.

#tail

tail :: forall f a. Cofree f a -> f (Cofree f a)

Returns the "subtrees" of a tree.

#hoistCofree

hoistCofree :: forall f g. Functor f => (f ~> g) -> (Cofree f) ~> (Cofree g)

#buildCofree

buildCofree :: forall f s a. Functor f => (s -> Tuple a (f s)) -> s -> Cofree f a

Recursively unfolds a Cofree structure given a seed.

#explore

explore :: forall f g a b. Functor f => Functor g => (forall x y. f (x -> y) -> g x -> y) -> Free f (a -> b) -> Cofree g a -> b

Explore a value in the cofree comonad by using an expression in a corresponding free monad.

The free monad should be built from a functor which pairs with the functor underlying the cofree comonad.

#exploreM

exploreM :: forall f g a b m. Functor f => Functor g => MonadRec m => (forall x y. f (x -> y) -> g x -> m y) -> Free f (a -> b) -> Cofree g a -> m b

Modules