pipes-2.0.0: Compositional pipelines

Safe HaskellSafe-Infered

Control.Monad.Trans.Free

Contents

Description

Every functor f gives rise to a corresponding free monad: Free f.

A free monad over a functor resembles a "list" of that functor:

  • pure behaves like [] by not using the functor at all
  • wrap behaves like (:) by prepending another layer of the functor

Synopsis

The Free monad

data FreeF f r x Source

Constructors

Pure r 
Wrap (f x) 

type Free f = FreeT f IdentitySource

The Free type is isomorphic to:

 data Free f r = Pure r | Wrap (f (Free f r))

... except that if you want to pattern match against those constructors, you must first use runFree to unwrap the value first.

Similarly, you don't use the raw constructors to build a value of type Free. You instead use the smart constructors pure (from Control.Applicative) and wrap.

wrap :: Monad m => f (FreeT f m r) -> FreeT f m rSource

runFree :: Free f r -> FreeF f r (Free f r)Source

The FreeT monad transformer

data FreeT f m r Source

A free monad transformer alternates nesting the base functor f and the base monad m.

  • f - The functor that generates the free monad
  • m - The base monad
  • r - The type of the return value

This type commonly arises in coroutine/iteratee libraries under various names.

Constructors

FreeT 

Fields

runFreeT :: m (FreeF f r (FreeT f m r))
 

Instances

MonadTrans (FreeT f) 
(Functor f, Monad m) => Monad (FreeT f m) 
(Functor f, Monad m) => Functor (FreeT f m) 
(Functor f, Monad m) => Applicative (FreeT f m)