Maintainer | Ralf Laemmel, Joost Visser |
---|---|

Stability | experimental |

Portability | portable |

Safe Haskell | None |

Language | Haskell98 |

This module is part of `StrategyLib`

, a library of functional strategy
combinators, including combinators for generic traversal. This module
provides combinators to localize monadic effects.

- mrunTP :: (Monad m, Monad m', MonadRun s m) => (forall a. s a a) -> TP m -> TP m'
- mrunTU :: (Monad m, Monad m', MonadRun s m) => s a a -> TU a m -> TU a m'
- liftTP :: (Monad (t m), Monad m, MonadTrans t) => TP m -> TP (t m)
- liftTU :: (Monad (t m), Monad m, MonadTrans t) => TU a m -> TU a (t m)
- unliftTP :: (Monad (t m), Monad m, MonadUnTrans s t) => (forall a. s a a) -> TP (t m) -> TP m
- unliftTU :: (Monad (t m), Monad m, MonadUnTrans s t) => s a a -> TU a (t m) -> TU a m
- guaranteeSuccessTP :: (Monad (t m), Monad m, MonadUnTrans MaybeAlg t) => (forall a. a) -> TP (t m) -> TP m
- guaranteeSuccessTU :: (Monad (t m), Monad m, MonadUnTrans MaybeAlg t) => a -> TU a (t m) -> TU a m
- unsafeGuaranteeSuccessTP :: (Monad (t m), Monad m, MonadUnTrans MaybeAlg t) => TP (t m) -> TP m
- localStateTP :: (Monad (t m), Monad m, MonadUnTrans (StateAlg s) t) => s -> TP (t m) -> TP m
- localStateTU :: (Monad (t m), Monad m, MonadUnTrans (StateAlg s) t) => s -> TU a (t m) -> TU a m

# Replace one strategy monad by another

mrunTP :: (Monad m, Monad m', MonadRun s m) => (forall a. s a a) -> TP m -> TP m' Source

Replace the monad in a type-preserving strategy, given a monad
algebra (see `MonadRun`

) for the monad that is replaced. The two
monads are unrelated, so none of the effects in the monad that is
replaced carry over to the one that replaces it.

mrunTU :: (Monad m, Monad m', MonadRun s m) => s a a -> TU a m -> TU a m' Source

Replace the monad in a type-unifying strategy, given a monad
algebra (see `MonadRun`

) for the monad that is replaced. The two
monads are unrelated, so none of the effects in the monad that is
replaced carry over to the one that replaces it.

# Add an effect to the strategy monad

liftTP :: (Monad (t m), Monad m, MonadTrans t) => TP m -> TP (t m) Source

Add an effect to the monad in a type-preserving strategy.
The monads are related by a monad transformer, so the effects of the
incoming monad are preserved in the result monad. We use the `lift`

function of the monad transformer.

liftTU :: (Monad (t m), Monad m, MonadTrans t) => TU a m -> TU a (t m) Source

Add an effect to the monad in a type-unifying strategy.
The monads are related by a monad transformer, so the effects of the
incoming monad are preserved in the result monad. We use the `lift`

function of the monad transformer.

# Remove an effect from the strategy monad

unliftTP :: (Monad (t m), Monad m, MonadUnTrans s t) => (forall a. s a a) -> TP (t m) -> TP m Source

remove an effect from the monad of a type-preserving strategy.
The monads are related by a monad untransformer (see `MonadUnTrans`

),
so the effects of the incoming monad are preserved in the result
monad, except for the effect for which a monad algebra is supplied.

unliftTU :: (Monad (t m), Monad m, MonadUnTrans s t) => s a a -> TU a (t m) -> TU a m Source

remove an effect from the monad of a type-unifying strategy.
The monads are related by a monad untransformer (see `MonadUnTrans`

),
so the effects of the incoming monad are preserved in the result
monad, except for the effect for which a monad algebra is supplied.

# Localize specific effects

## Localize the partiality effect

:: (Monad (t m), Monad m, MonadUnTrans MaybeAlg t) | |

=> (forall a. a) | default value (Note: universally quantified!) |

-> TP (t m) | type-preserving partial strategy |

-> TP m | type-preserving strategy without partiality |

Localize the partiality effect in a type-preserving strategy. A
default value must be supplied to be used to recover from
failure. Since this default parameter is universally quantified,
only `undefined`

and 'error ...' can be used to instantiate it.
See also 'unsafeGuaranteeSuccessTP.

:: (Monad (t m), Monad m, MonadUnTrans MaybeAlg t) | |

=> a | default value |

-> TU a (t m) | type-preserving partial strategy |

-> TU a m | type-preserving strategy without partiality |

Localize the partiality effect in a type-unifying strategy. A default value must be supplied to be used to recover from failure.

unsafeGuaranteeSuccessTP :: (Monad (t m), Monad m, MonadUnTrans MaybeAlg t) => TP (t m) -> TP m Source

Unsafe version of `guaranteeSuccessTP`

. This version uses uses `undefined`

to recover from failure. For the type-preserving case, this is the only
possible default value.

## Localize the state effect

localStateTP :: (Monad (t m), Monad m, MonadUnTrans (StateAlg s) t) => s -> TP (t m) -> TP m Source

Localize the state of a type-preserving strategy. The first argument represents the initial state.

localStateTU :: (Monad (t m), Monad m, MonadUnTrans (StateAlg s) t) => s -> TU a (t m) -> TU a m Source

Localize the state of a type-unifying strategy. The first argument represents the initial state.