free-3.2: Monads for free

PortabilityMPTCs, fundeps
MaintainerEdward Kmett <>
Safe HaskellNone



The cofree comonad transformer



newtype CofreeT f w a Source

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




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


(Comonad (CofreeT f w), Functor f, Comonad w) => ComonadCofree f (CofreeT f w) 
Functor f => ComonadTrans (CofreeT f) 
(Functor f, Functor w) => Functor (CofreeT f w) 
(Typeable1 f, Typeable1 w) => Typeable1 (CofreeT f w) 
(Foldable f, Foldable w) => Foldable (CofreeT f w) 
(Functor (CofreeT f w), Foldable (CofreeT f w), Traversable f, Traversable w) => Traversable (CofreeT f w) 
(Functor (CofreeT f w), Functor f, Comonad w) => Comonad (CofreeT f w) 
Eq (w (CofreeF f a (CofreeT f w a))) => Eq (CofreeT f w a) 
(Typeable (CofreeT f w a), Typeable1 f, Typeable1 w, Typeable a, Data (w (CofreeF f a (CofreeT f w a))), Data a) => Data (CofreeT f w a) 
(Eq (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) 

data CofreeF f a b Source

This is the base functor of the cofree comonad transformer.


a :< (f b) 


Typeable1 f => Typeable2 (CofreeF f) 
(Bifunctor (CofreeF f), Bifoldable (CofreeF f), Traversable f) => Bitraversable (CofreeF f) 
Functor f => Bifunctor (CofreeF f) 
Foldable f => Bifoldable (CofreeF f) 
Functor f => Functor (CofreeF f a) 
Foldable f => Foldable (CofreeF f a) 
(Functor (CofreeF f a), Foldable (CofreeF f a), Traversable f) => Traversable (CofreeF f a) 
(Eq a, Eq (f b)) => Eq (CofreeF f a b) 
(Typeable (CofreeF f a b), Typeable1 f, Typeable a, Typeable b, Data a, Data (f b), Data b) => Data (CofreeF f a b) 
(Eq (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 whereSource

Allows you to peel a layer off a cofree comonad.


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

Remove a layer.

headF :: CofreeF f a b -> aSource

Extract the head of the base functor

tailF :: CofreeF f a b -> f bSource

Extract the tails of the base functor