Module

Control.Monad.Free

Package
purescript-free
Repository
purescript/purescript-free

#Free Source

data Free :: (Type -> Type) -> Type -> Typedata 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 f a. 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 f g. (f ~> g) -> (Free f) ~> (Free g)

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

#foldFree Source

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.

#substFree Source

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.

#runFree Source

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.

#runFreeM Source

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.

#resume Source

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

Unwraps a single layer of the functor f.

#resume' Source

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

Unwraps a single layer of f, providing the continuation.