Module

Control.Monad.Free

Package
purescript-free
Repository
purescript/purescript-free

#Free Source

data Free f a

The free monad for a type constructor f.

Implemented in the spirit of Reflection without Remorse, the free monad is represented using a sequential data structure in order to overcome the quadratic complexity of left-associated binds and traversal through the free monad structure.

Instances

#suspendF Source

suspendF :: forall f. Applicative f => (Free f) ~> (Free f)

Suspend a value given the applicative functor f into the free monad.

#wrap Source

wrap :: forall a f. f (Free f a) -> Free f a

Add a layer.

#liftF Source

liftF :: forall f. f ~> (Free f)

Lift an impure value described by the generating type constructor f into the free monad.

#hoistFree Source

hoistFree :: forall g f. (f ~> g) -> (Free f) ~> (Free g)

Use a natural transformation to change the generating type constructor of a free monad.

#foldFree Source

foldFree :: forall m f. MonadRec m => (f ~> m) -> (Free f) ~> m

Run a free monad with a natural transformation from the type constructor f to the tail-recursive monad m. See the MonadRec type class for more details.

#substFree Source

substFree :: forall g f. (f ~> (Free g)) -> (Free f) ~> (Free g)

Like foldFree, but for folding into some other Free monad without the overhead that MonadRec incurs.

#runFree Source

runFree :: forall a f. Functor f => (f (Free f a) -> Free f a) -> Free f a -> a

Run a free monad with a function that unwraps a single layer of the functor f at a time.

#runFreeM Source

runFreeM :: forall a m f. Functor f => MonadRec m => (f (Free f a) -> m (Free f a)) -> Free f a -> m a

Run a free monad with a function mapping a functor f to a tail-recursive monad m. See the MonadRec type class for more details.

#resume Source

resume :: forall a f. Functor f => Free f a -> Either (f (Free f a)) a

Unwraps a single layer of the functor f.

#resume' Source

resume' :: forall r a f. (forall b. f b -> (b -> Free f a) -> r) -> (a -> r) -> Free f a -> r

Unwraps a single layer of f, providing the continuation.