Strafunski-StrategyLib-5.0.0.9: Library for strategic programming

MaintainerRalf Laemmel, Joost Visser
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Control.Monad.Run

Contents

Description

This module is part of StrategyLib, a library of functional strategy combinators, including combinators for generic traversal. This module provides non-strategic functionality for running monads and unlifting monad transformers. In a sense, this is dual to the return and lift functionality of the Monad and MonadTrans classes.

Synopsis

Monad algebras

data MaybeAlg a b Source #

The algebra for the partiality effect of Maybe and MaybeT.

Constructors

MaybeAlg 

Fields

Instances

MonadUnTrans MaybeAlg MaybeT Source #

Unlifting the partiality monad transformer.

Methods

unlift :: Monad m => MaybeAlg a b -> MaybeT m a -> m b Source #

MonadRun MaybeAlg Maybe Source #

Running the Maybe monad.

Methods

run :: MaybeAlg a b -> Maybe a -> b Source #

data ErrorAlg e a b Source #

The algebra for the error effect of Either and ErrorT.

Constructors

ErrorAlg 

Fields

Instances

MonadUnTrans (ErrorAlg e) (ErrorT e) Source #

Unlifting the error monad transformer.

Methods

unlift :: Monad m => ErrorAlg e a b -> ErrorT e m a -> m b Source #

MonadRun (ErrorAlg e) (Either e) Source #

Running the error monad.

Methods

run :: ErrorAlg e a b -> Either e a -> b Source #

data ListAlg a b Source #

The algebra for the non-determinacy effect of '[]' and ListT.

Constructors

ListAlg 

Fields

Instances

MonadUnTrans ListAlg ListT Source #

Unlifting the list monad transformer.

Methods

unlift :: Monad m => ListAlg a b -> ListT m a -> m b Source #

MonadRun ListAlg [] Source #

Running the list monad.

Methods

run :: ListAlg a b -> [a] -> b Source #

data StateAlg s a b Source #

The algebra for the state effect of State and StateT.

Constructors

StateAlg 

Fields

  • first :: s

    initial state

  • next :: (a, s) -> b

    state transformer

Instances

MonadUnTrans (StateAlg s) (StateT s) Source #

Unlifting the state monad transformer

Methods

unlift :: Monad m => StateAlg s a b -> StateT s m a -> m b Source #

MonadRun (StateAlg s) (State s) Source #

Running the State monad.

Methods

run :: StateAlg s a b -> State s a -> b Source #

Running monads

class MonadRun s m | m -> s where Source #

The class of monads for which a run function is defined that executes the computation of the monad.

Minimal complete definition

run

Methods

run :: s a b -> m a -> b Source #

The overloaded function run takes as first argument an "algebra" which captures the ingredients necessary to run the particular monad at hand. This algebra is parameterized with the domain and co-domain of run.

Instances

MonadRun (->) IO Source #

Running the IO monad. Note: uses unsafePerformIO!

Methods

run :: (a -> b) -> IO a -> b Source #

MonadRun (->) Identity Source #

Running the Identity monad. The algebra for the Identity monad is a unary function.

Methods

run :: (a -> b) -> Identity a -> b Source #

MonadRun ListAlg [] Source #

Running the list monad.

Methods

run :: ListAlg a b -> [a] -> b Source #

MonadRun MaybeAlg Maybe Source #

Running the Maybe monad.

Methods

run :: MaybeAlg a b -> Maybe a -> b Source #

MonadRun (StateAlg s) (State s) Source #

Running the State monad.

Methods

run :: StateAlg s a b -> State s a -> b Source #

MonadRun (ErrorAlg e) (Either e) Source #

Running the error monad.

Methods

run :: ErrorAlg e a b -> Either e a -> b Source #

mrun :: (MonadRun s m, Monad m') => s a b -> m a -> m' b Source #

Exchange one monad by another. This function runs one monad, and puts its value in another. This is basically a monadic version of the run function itself. Note that the two monads are unrelated, so none of the effects of the incoming monad are transferred to the result monad.

Unlifting monad transformers

class MonadUnTrans s t | t -> s where Source #

Just as a base monad can be run to remove the monad, so can a transformed monad be unlifted to remove the transformer and obtain the original monad.

Minimal complete definition

unlift

Methods

unlift :: Monad m => s a b -> t m a -> m b Source #

The overloaded function unlift for monad transformers takes as first argument an "algebra" just like the run function for base monads. For each monad transformer, the same algebra is used as for the base monad of which the transformer is the parameterized variant.

Instances

MonadUnTrans ListAlg ListT Source #

Unlifting the list monad transformer.

Methods

unlift :: Monad m => ListAlg a b -> ListT m a -> m b Source #

MonadUnTrans MaybeAlg MaybeT Source #

Unlifting the partiality monad transformer.

Methods

unlift :: Monad m => MaybeAlg a b -> MaybeT m a -> m b Source #

MonadUnTrans (StateAlg s) (StateT s) Source #

Unlifting the state monad transformer

Methods

unlift :: Monad m => StateAlg s a b -> StateT s m a -> m b Source #

MonadUnTrans (ErrorAlg e) (ErrorT e) Source #

Unlifting the error monad transformer.

Methods

unlift :: Monad m => ErrorAlg e a b -> ErrorT e m a -> m b Source #

Monadic choice combinators that confine the partiality effect

Monadic choice

mplus' :: (Monad m, MonadUnTrans MaybeAlg t) => t m b -> m b -> m b Source #

Monadic choice combinator that confines the partiality effect to the first argument. This is a variation on mplus which allows the partiality effect to spread to both arguments and to the result.

mswitch Source #

Arguments

:: (Monad m, MonadUnTrans MaybeAlg t) 
=> [t m b]

choice branches

-> m b

otherwise

-> m b

result

Monadic choice combinator. Generalization of mplus' that takes a list of choice arguments rather than a single one.

mayswitch :: Monad m => [MaybeT m b] -> m b -> m b Source #

Specialization of mswitch for MaybeT.

Monadic function choice

mchoice' :: (Monad m, MonadUnTrans MaybeAlg t) => (a -> t m b) -> (a -> m b) -> a -> m b Source #

Monadic function choice combinator that confines the partiality effect to the first argument. This is a variation on mchoice which allows the partiality effect to spread to both arguments and to the result.

mchoices :: (Monad m, MonadUnTrans MaybeAlg t, MonadPlus (t m)) => [a -> t m b] -> (a -> m b) -> a -> m b Source #

Monadic function choice combinator. Generalization of mchoice' that takes a list of choice arguments rather than a single one.

Implementation variants

mswitch0 :: (Monad m, MonadUnTrans MaybeAlg t) => [t m b] -> m b -> m b Source #

Implementation variant of mswitch in terms of foldr.

mswitch1 :: (Monad m, MonadUnTrans MaybeAlg t) => [t m b] -> m b -> m b Source #

Implementation variant of mswitch with mplus' expanded:

mswitch' :: (Monad m, MonadUnTrans MaybeAlg t, MonadPlus (t m)) => [t m b] -> m b -> m b Source #

Implementation variant of mswitch where the unlift is postponed to the very end.