Module

Control.Cofree

Package
purescript-concur-core
Repository
purescript-concur/purescript-concur-core

AJ: This is the same as Control.Comonad.Cofree from the purescript-free package. However, we need to override the applicative and monad instance, and "probably" due to a Purescript bug it's not working. The cofree comonad for a Functor. This version also adds lazyCofree, lazyHead, lazyTail, and mfix

#Cofree Source

newtype 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

#(:<) Source

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

#buildCofree Source

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

Recursively unfolds a Cofree structure given a seed.

#lazyCofree Source

lazyCofree :: forall a f. Lazy (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".

#deferCofree Source

deferCofree :: forall a f. (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".

#explore Source

explore :: forall b a g f. Functor f => Functor g => (forall y x. 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 Source

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

#head Source

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

Returns the label for a tree.

#lazyHead Source

lazyHead :: forall a f. Cofree f a -> (Lazy a)

Like head, but returns a lazy value

#hoistCofree Source

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

#mkCofree Source

mkCofree :: forall a f. 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".

#tail Source

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

Returns the "subtrees" of a tree.

#lazyTail Source

lazyTail :: forall a f. Cofree f a -> (Lazy (f (Cofree f a)))

Like tail, but returns a lazy value

#mfix Source

mfix :: forall a f. (Lazy a -> Cofree f a) -> Cofree f a

#unfoldCofree Source

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

This signature is deprecated and will be replaced by buildCofree in a future release.