Data.Generics.Strafunski.StrategyLib.EffectTheme
 Portability portable Stability experimental Maintainer Ralf Laemmel, Joost Visser
 Contents Replace one strategy monad by another Add an effect to the strategy monad Remove an effect from the strategy monad Localize specific effects Localize the partiality effect Localize the state effect
Description
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.
Synopsis
Replace one strategy monad by another
mrunTP :: (Monad m, Monad m', MonadRun s m) => (forall a . s a a) -> TP m -> TP m'
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'
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 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)
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
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
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
guaranteeSuccessTP
 :: (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.
guaranteeSuccessTU
 :: (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
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
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
Localize the state of a type-unifying strategy. The first argument represents the initial state.