Module

Control.Monad.Free

Package
purescript-free
Repository
purescript/purescript-free

#FreeSource

data Free f a

The free monad for a type constructor f.

Implemented in the spirit of Relection 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

#liftFSource

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

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

#liftFISource

liftFI :: forall f g. Inject f g => f ~> (Free g)

Lift an action described by the generating type constructor f into Free g using Inject to go from f to g.

#suspendFSource

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

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

#hoistFreeSource

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

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

#injFSource

injF :: forall f g. Inject f g => (Free f) ~> (Free g)

Embed computations in one Free monad as computations in the Free monad for a coproduct type constructor.

This construction allows us to write computations which are polymorphic in the particular Free monad we use, allowing us to extend the functionality of our monad later.

#foldFreeSource

foldFree :: forall f m. 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.

#substFreeSource

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

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

#runFreeSource

runFree :: forall f a. 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.

#runFreeMSource

runFreeM :: forall f m a. (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.

#resumeSource

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

Unwraps a single layer of the functor f.