free-4.9: Monads for free

PortabilityMPTCs, fundeps
MaintainerEdward Kmett <>
Safe HaskellNone




The coiterative comonad generated by a comonad



Coiterative comonads represent non-terminating, productive computations.

They are the dual notion of iterative monads. While iterative computations produce no values or eventually terminate with one, coiterative computations constantly produce values and they never terminate.

It's simpler form, Coiter, is an infinite stream of data. CoiterT extends this so that each step of the computation can be performed in a comonadic context.

The coiterative comonad transformer

newtype CoiterT w a Source

This is the coiterative comonad generated by a comonad




runCoiterT :: w (a, CoiterT w a)


ComonadHoist CoiterT 
ComonadTrans CoiterT 
ComonadTraced m w => ComonadTraced m (CoiterT w) 
ComonadStore s w => ComonadStore s (CoiterT w) 
ComonadEnv e w => ComonadEnv e (CoiterT w) 
Comonad w => ComonadCofree Identity (CoiterT w) 
Functor w => Functor (CoiterT w) 
Typeable1 w => Typeable1 (CoiterT w) 
Foldable w => Foldable (CoiterT w) 
Traversable w => Traversable (CoiterT w) 
Comonad w => Comonad (CoiterT w) 
(Functor w, Eq1 w) => Eq1 (CoiterT w) 
(Functor w, Ord1 w) => Ord1 (CoiterT w) 
(Functor w, Show1 w) => Show1 (CoiterT w) 
(Functor w, Read1 w) => Read1 (CoiterT w) 
Eq (w (a, CoiterT w a)) => Eq (CoiterT w a) 
(Typeable1 w, Typeable a, Data (w (a, CoiterT w a)), Data a) => Data (CoiterT w a) 
Ord (w (a, CoiterT w a)) => Ord (CoiterT w a) 
Read (w (a, CoiterT w a)) => Read (CoiterT w a) 
Show (w (a, CoiterT w a)) => Show (CoiterT w a) 

The coiterative comonad

type Coiter = CoiterT IdentitySource

The coiterative comonad

coiter :: a -> Coiter a -> Coiter aSource

Prepends a result to a coiterative computation.

runCoiter . uncurry coiter == id

runCoiter :: Coiter a -> (a, Coiter a)Source

Extracts the first result from a coiterative computation.

uncurry coiter . runCoiter == id

Generating coiterative comonads

unfold :: Comonad w => (w a -> a) -> w a -> CoiterT w aSource

Unfold a CoiterT comonad transformer from a cokleisli arrow and an initial comonadic seed.

Cofree comonads

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.