Strafunski-StrategyLib-5.0.0.3: Library for strategic programming

Portabilityportable
Stabilityexperimental
MaintainerRalf Laemmel, Joost Visser
Safe HaskellNone

Data.Generics.Strafunski.StrategyLib.FlowTheme

Contents

Description

This module is part of StrategyLib, a library of functional strategy combinators, including combinators for generic traversal. This module defines combinators to wire up control and data flow. Whenever possible, we define the combinators in an overloaded fashion but we provide type-specialised variants for TP and TU for convenience.

Synopsis

Try: recover from failure

tryS :: (StrategyPlus s m, StrategyMonoid s m) => s m -> s mSource

Attempt a strategy s, but recover if it fails.

tryTP :: MonadPlus m => TP m -> TP mSource

Attempt a type-preserving strategy s, but if it fails, return the input term unchanged.

tryTU :: (MonadPlus m, Monoid u) => TU u m -> TU u mSource

Attempt a type-unifying strategy s, but if it fails, return the mempty element of a Monoid.

Test: ignore result, but retain effects

testS :: Strategy s m => s m -> TP mSource

Test for a strategy's success in a type-preserving context.

testTP :: Monad m => TP m -> TP mSource

Test for a type-preserving strategy's success in a type-preserving context.

testTU :: Monad m => TU a m -> TP mSource

Test for a type-unifying strategy's success in a type-preserving context.

If-then-else: pass value from condition to then-clause

ifS :: StrategyPlus s m => TU u m -> (u -> s m) -> s m -> s mSource

If c succeeds, pass its value to the then-clause t, otherwise revert to the else-clause e.

ifTP :: MonadPlus m => TU u m -> (u -> TP m) -> TP m -> TP mSource

If c succeeds, pass its value to the then-clause t, otherwise revert to the else-clause e.

ifTU :: MonadPlus m => TU u m -> (u -> TU u' m) -> TU u' m -> TU u' mSource

If c succeeds, pass its value to the then-clause t, otherwise revert to the else-clause e.

If-then: disciplined form of a guarding

ifthenS :: Strategy s m => TU () m -> s m -> s mSource

Guard then-clause t by the void-valued type-unifying condition c.

ifthenTP :: Monad m => TU () m -> TP m -> TP mSource

Guard type-preserving then-clause t by the void-valued type-unifying condition c.

ifthenTU :: Monad m => TU () m -> TU u m -> TU u mSource

Guard type-unifying then-clause t by the void-valued type-unifying condition c.

Not: negation by failure

notS :: StrategyPlus s m => s m -> TP mSource

Invert the success-value of strategy s.

notTP :: MonadPlus m => TP m -> TP mSource

Invert the success-value of type-preserving strategy s. Its output term (in case of success) will be ignored.

notTU :: MonadPlus m => TU u m -> TP mSource

Invert the success-value of type-unifying strategy s. Its output value (in case of success) will be ignored.

Exclusive choice

xchoiceS :: StrategyPlus s m => s m -> s m -> s mSource

Succeed if exactly one argument strategy succeeds.

xchoiceTP :: MonadPlus m => TP m -> TP m -> TP mSource

Succeed if exactly one argument strategy succeeds.

xchoiceTU :: MonadPlus m => TU u m -> TU u m -> TU u mSource

Succeed if exactly one argument strategy succeeds.

Generic filter, derived from monomorphic predicate

filterTP :: (Term t, MonadPlus m) => (t -> Bool) -> TP mSource

If predicate g holds for the input term, return it as output term, otherwise fail.

filterTU :: (Term t, MonadPlus m) => (t -> Bool) -> TU t mSource

If predicate g holds for the input term, return it as output value, otherwise fail.

Generic ticker, derived from monomorphic predicate

tickTU :: (Monad m, Term t, Num n) => (t -> Bool) -> TU n mSource

If predicate g holds for the input term, return 1 otherwise return 0.

Type guards

type TypeGuard a = a -> ()Source

Type guard (function type), i.e., guard that does not observe values

typeGuard :: TypeGuard aSource

Type guard (function). Typical usage:

 
   full_tdTU (typeTickTU (typeGuard::TypeGuard MyType))

Generic ticker, derived from type guard

typeTickTU :: (Term t, Monad m, Num n) => TypeGuard t -> TU n mSource

If type guard holds for the input term, return 1 otherwise return 0.

Generic filters, derived from type guard

typeFilterTP :: (Term t, MonadPlus m) => TypeGuard t -> TP mSource

If type guard holds for the input term, return it as output term, otherwise fail.

typeFilterTU :: (Term t, MonadPlus m) => TypeGuard t -> TU t mSource

If type guard holds for the input term, return it as output value, otherwise fail.