pipes-2.0.0: Compositional pipelines

Safe HaskellSafe
LanguageHaskell2010

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 Identity Source #

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 r Source #

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

Instances

MonadTrans (FreeT f) Source # 

Methods

lift :: Monad m => m a -> FreeT f m a #

(Functor f, Monad m) => Monad (FreeT f m) Source # 

Methods

(>>=) :: FreeT f m a -> (a -> FreeT f m b) -> FreeT f m b #

(>>) :: FreeT f m a -> FreeT f m b -> FreeT f m b #

return :: a -> FreeT f m a #

fail :: String -> FreeT f m a #

(Functor f, Monad m) => Functor (FreeT f m) Source # 

Methods

fmap :: (a -> b) -> FreeT f m a -> FreeT f m b #

(<$) :: a -> FreeT f m b -> FreeT f m a #

(Functor f, Monad m) => Applicative (FreeT f m) Source # 

Methods

pure :: a -> FreeT f m a #

(<*>) :: FreeT f m (a -> b) -> FreeT f m a -> FreeT f m b #

(*>) :: FreeT f m a -> FreeT f m b -> FreeT f m b #

(<*) :: FreeT f m a -> FreeT f m b -> FreeT f m a #