Control.Comonad.Trans.Cofree

free-4.12.4: Monads for free

Copyright | (C) 2008-2013 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | MPTCs, fundeps
Safe Haskell | Safe
Language | Haskell2010

Control.Comonad.Trans.Cofree

Description

The cofree comonad transformer

Synopsis

- newtype CofreeT f w a = CofreeT {
  - runCofreeT :: w (CofreeF f a (CofreeT f w a))
  }
- type Cofree f = CofreeT f Identity
- cofree :: CofreeF f a (Cofree f a) -> Cofree f a
- runCofree :: Cofree f a -> CofreeF f a (Cofree f a)
- data CofreeF f a b = a :< (f b)
- class (Functor f, Comonad w) => ComonadCofree f w | w -> f where
  - unwrap :: w a -> f (w a)
- headF :: CofreeF f a b -> a
- tailF :: CofreeF f a b -> f b
- transCofreeT :: (Functor g, Comonad w) => (forall x. f x -> g x) -> CofreeT f w a -> CofreeT g w a
- coiterT :: (Functor f, Comonad w) => (w a -> f (w a)) -> w a -> CofreeT f w a

# Documentation

newtype CofreeT f w a

This is a cofree comonad of some functor `f`, with a comonad `w` threaded through it at each level.

Constructors

CofreeT |
Fields runCofreeT :: w (CofreeF f a (CofreeT f w a))

Instances

(Functor f, ComonadEnv e w) => ComonadEnv e (CofreeT f w) |
(Functor f, Comonad w) => ComonadCofree f (CofreeT f w) |
Functor f => ComonadHoist (CofreeT f) |
ComonadTrans (CofreeT f) |
Alternative f => MonadTrans (CofreeT f) |
(Alternative f, Monad w) => Monad (CofreeT f w) |
(Functor f, Functor w) => Functor (CofreeT f w) |
(Alternative f, Applicative w) => Applicative (CofreeT f w) |
(Foldable f, Foldable w) => Foldable (CofreeT f w) |
(Traversable f, Traversable w) => Traversable (CofreeT f w) |
(Alternative f, MonadZip f, MonadZip m) => MonadZip (CofreeT f m) |
(Functor f, Comonad w) => Comonad (CofreeT f w) |
Eq (w (CofreeF f a (CofreeT f w a))) => Eq (CofreeT f w a) |
(Typeable (* -> *) f, Typeable (* -> *) w, Typeable * a, Data (w (CofreeF f a (CofreeT f w a))), Data a) => Data (CofreeT f w a) |
Ord (w (CofreeF f a (CofreeT f w a))) => Ord (CofreeT f w a) |
Read (w (CofreeF f a (CofreeT f w a))) => Read (CofreeT f w a) |
Show (w (CofreeF f a (CofreeT f w a))) => Show (CofreeT f w a) |

type Cofree f = CofreeT f Identity

The cofree `Comonad` of a functor `f`.

cofree :: CofreeF f a (Cofree f a) -> Cofree f a

Wrap another layer around a cofree comonad value.

`cofree` is a right inverse of `runCofree`.

    runCofree . cofree == id

runCofree :: Cofree f a -> CofreeF f a (Cofree f a)

Unpeel the first layer off a cofree comonad value.

`runCofree` is a right inverse of `cofree`.

    cofree . runCofree == id

data CofreeF f a b

This is the base functor of the cofree comonad transformer.

Constructors

a :< (f b) infixr 5 |

Instances

Functor f => Bifunctor (CofreeF f) |
Traversable f => Bitraversable (CofreeF f) |
Foldable f => Bifoldable (CofreeF f) |
Functor f => Functor (CofreeF f a) |
Foldable f => Foldable (CofreeF f a) |
Traversable f => Traversable (CofreeF f a) |
(Eq a, Eq (f b)) => Eq (CofreeF f a b) |
(Typeable (* -> *) f, Typeable * a, Typeable * b, Data a, Data (f b), Data b) => Data (CofreeF f a b) |
(Ord a, Ord (f b)) => Ord (CofreeF f a b) |
(Read a, Read (f b)) => Read (CofreeF f a b) |
(Show a, Show (f b)) => Show (CofreeF f a b) |

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

Allows you to peel a layer off a cofree comonad.

Methods

unwrap :: w a -> f (w a)

Remove a layer.

Instances

ComonadCofree [] Tree |
ComonadCofree Maybe NonEmpty |
ComonadCofree f w => ComonadCofree f (IdentityT w) |
Functor f => ComonadCofree f (Cofree f) |
Comonad w => ComonadCofree Identity (CoiterT w) |
(ComonadCofree f w, 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) |
ComonadCofree (Const b) ((,) b) |

headF :: CofreeF f a b -> a

Extract the head of the base functor

tailF :: CofreeF f a b -> f b

Extract the tails of the base functor

transCofreeT :: (Functor g, Comonad w) => (forall x. f x -> g x) -> CofreeT f w a -> CofreeT g w a

Lift a natural transformation from `f` to `g` into a comonad homomorphism from ``CofreeT` f w` to ``CofreeT` g w`

coiterT :: (Functor f, Comonad w) => (w a -> f (w a)) -> w a -> CofreeT f w a

Unfold a `CofreeT` comonad transformer from a coalgebra and an initial comonad.