Maintainer | bastiaan.heeren@ou.nl |
---|---|

Stability | provisional |

Portability | portable (depends on ghc) |

Safe Haskell | None |

Language | Haskell98 |

A strategy is a context-free grammar with rules as symbols. Strategies can be labeled with strings. A type class is introduced to lift all the combinators that work on strategies, only to prevent that you have to insert these lifting functions yourself.

- data Strategy a
- data LabeledStrategy a
- class IsStrategy f where
- toStrategy :: f a -> Strategy a

- derivationList :: IsStrategy f => (Rule a -> Rule a -> Ordering) -> f a -> a -> [Derivation (Rule a, Environment) a]
- (<*>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a
- (<|>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a
- (<%>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a
- succeed :: Strategy a
- fail :: Strategy a
- atomic :: IsStrategy f => f a -> Strategy a
- label :: (IsId l, IsStrategy f) => l -> f a -> LabeledStrategy a
- sequence :: IsStrategy f => [f a] -> Strategy a
- alternatives :: IsStrategy f => [f a] -> Strategy a
- interleave :: IsStrategy f => [f a] -> Strategy a
- permute :: IsStrategy f => [f a] -> Strategy a
- fix :: (Strategy a -> Strategy a) -> Strategy a
- many :: IsStrategy f => f a -> Strategy a
- many1 :: IsStrategy f => f a -> Strategy a
- replicate :: IsStrategy f => Int -> f a -> Strategy a
- option :: IsStrategy f => f a -> Strategy a
- check :: (a -> Bool) -> Strategy a
- not :: IsStrategy f => f a -> Strategy a
- repeat :: IsStrategy f => f a -> Strategy a
- repeat1 :: IsStrategy f => f a -> Strategy a
- try :: IsStrategy f => f a -> Strategy a
- (|>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a
- (>|>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a
- exhaustive :: IsStrategy f => [f a] -> Strategy a
- while :: IsStrategy f => (a -> Bool) -> f a -> Strategy a
- until :: IsStrategy f => (a -> Bool) -> f a -> Strategy a
- multi :: (IsId l, IsStrategy f) => l -> f a -> Strategy a
- type DependencyGraph node key = (Graph, Vertex -> (node, key, [key]), key -> Maybe Vertex)
- dependencyGraph :: IsStrategy f => DependencyGraph (f a) key -> Strategy a
- module Ideas.Common.Strategy.Traversal
- module Ideas.Common.Strategy.Configuration
- remove :: IsStrategy f => f a -> Strategy a
- collapse :: IsStrategy f => f a -> Strategy a
- hide :: IsStrategy f => f a -> Strategy a
- strategyLocations :: LabeledStrategy a -> [([Int], Id)]
- checkLocation :: Id -> LabeledStrategy a -> Bool
- subTaskLocation :: LabeledStrategy a -> Id -> Id -> Id
- nextTaskLocation :: LabeledStrategy a -> Id -> Id -> Id
- data Prefix a
- emptyPrefix :: IsStrategy f => f a -> a -> Prefix a
- noPrefix :: Prefix a
- replayPath :: IsStrategy f => Path -> f a -> a -> ([Step a], Prefix a)
- replayPaths :: IsStrategy f => [Path] -> f a -> a -> Prefix a
- replayStrategy :: (Monad m, IsStrategy f) => Path -> f a -> a -> m (a, Prefix a)
- data Step a
- stepRule :: Step a -> Rule a
- stepEnvironment :: Step a -> Environment
- data Path
- emptyPath :: Path
- readPath :: Monad m => String -> m Path
- readPaths :: Monad m => String -> m [Path]
- prefixPaths :: Prefix a -> [Path]
- majorPrefix :: Prefix a -> Prefix a
- isEmptyPrefix :: Prefix a -> Bool
- cleanUpStrategy :: (a -> a) -> LabeledStrategy a -> LabeledStrategy a
- cleanUpStrategyAfter :: (a -> a) -> LabeledStrategy a -> LabeledStrategy a
- rulesInStrategy :: IsStrategy f => f a -> [Rule a]

# Data types and type classes

Abstract data type for strategies

data LabeledStrategy a Source

A strategy which is labeled with an identifier

class IsStrategy f where Source

Type class to turn values into strategies

toStrategy :: f a -> Strategy a Source

# Running strategies

derivationList :: IsStrategy f => (Rule a -> Rule a -> Ordering) -> f a -> a -> [Derivation (Rule a, Environment) a] Source

# Strategy combinators

## Basic combinators

(<*>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a infixr 5 Source

Put two strategies in sequence (first do this, then do that)

(<|>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a infixr 3 Source

Choose between the two strategies (either do this or do that)

(<%>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a infixr 2 Source

Interleave two strategies

atomic :: IsStrategy f => f a -> Strategy a Source

Makes a strategy atomic (w.r.t. parallel composition)

label :: (IsId l, IsStrategy f) => l -> f a -> LabeledStrategy a Source

sequence :: IsStrategy f => [f a] -> Strategy a Source

Puts a list of strategies into a sequence

alternatives :: IsStrategy f => [f a] -> Strategy a Source

Combines a list of alternative strategies

interleave :: IsStrategy f => [f a] -> Strategy a Source

Merges a list of strategies (in parallel)

permute :: IsStrategy f => [f a] -> Strategy a Source

Allows all permutations of the list

fix :: (Strategy a -> Strategy a) -> Strategy a Source

A fix-point combinator on strategies (to model recursion). Powerful (but dangerous) combinator

## EBNF combinators

many :: IsStrategy f => f a -> Strategy a Source

Repeat a strategy zero or more times (non-greedy)

many1 :: IsStrategy f => f a -> Strategy a Source

Apply a certain strategy at least once (non-greedy)

replicate :: IsStrategy f => Int -> f a -> Strategy a Source

Apply a strategy a certain number of times

option :: IsStrategy f => f a -> Strategy a Source

Apply a certain strategy or do nothing (non-greedy)

## Negation and greedy combinators

check :: (a -> Bool) -> Strategy a Source

Checks whether a predicate holds for the current term. The check is considered to be a minor step.

not :: IsStrategy f => f a -> Strategy a Source

Check whether or not the argument strategy cannot be applied: the result strategy only succeeds if this is not the case (otherwise it fails).

repeat :: IsStrategy f => f a -> Strategy a Source

Repeat a strategy zero or more times (greedy version of `many`

)

repeat1 :: IsStrategy f => f a -> Strategy a Source

Apply a certain strategy at least once (greedy version of `many1`

)

try :: IsStrategy f => f a -> Strategy a Source

Apply a certain strategy if this is possible (greedy version of `option`

)

(|>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a infixr 4 Source

Left-biased choice: if the left-operand strategy can be applied, do so. Otherwise, try the right-operand strategy

(>|>) :: (IsStrategy f, IsStrategy g) => f a -> g a -> Strategy a infixr 4 Source

Choose between the two strategies, with a preference for steps from the left hand-side strategy.

exhaustive :: IsStrategy f => [f a] -> Strategy a Source

Apply the strategies from the list exhaustively (until this is no longer possible)

while :: IsStrategy f => (a -> Bool) -> f a -> Strategy a Source

Repeat the strategy as long as the predicate holds

until :: IsStrategy f => (a -> Bool) -> f a -> Strategy a Source

Repeat the strategy until the predicate holds

multi :: (IsId l, IsStrategy f) => l -> f a -> Strategy a Source

Apply a strategy at least once, but collapse into a single step

## Graph

dependencyGraph :: IsStrategy f => DependencyGraph (f a) key -> Strategy a Source

Create a strategy from a dependency graph with strategies as nodes Does not check for cycles

## Traversal combinators

# Configuration combinators

remove :: IsStrategy f => f a -> Strategy a Source

collapse :: IsStrategy f => f a -> Strategy a Source

hide :: IsStrategy f => f a -> Strategy a Source

# Strategy locations

strategyLocations :: LabeledStrategy a -> [([Int], Id)] Source

Returns a list of all strategy locations, paired with the label

checkLocation :: Id -> LabeledStrategy a -> Bool Source

subTaskLocation :: LabeledStrategy a -> Id -> Id -> Id Source

nextTaskLocation :: LabeledStrategy a -> Id -> Id -> Id Source

# Prefixes

emptyPrefix :: IsStrategy f => f a -> a -> Prefix a Source

Construct the empty prefix for a labeled strategy

replayPath :: IsStrategy f => Path -> f a -> a -> ([Step a], Prefix a) Source

Construct a prefix for a path and a labeled strategy. The third argument is the current term.

replayPaths :: IsStrategy f => [Path] -> f a -> a -> Prefix a Source

Construct a prefix for a list of paths and a labeled strategy. The third argument is the current term.

replayStrategy :: (Monad m, IsStrategy f) => Path -> f a -> a -> m (a, Prefix a) Source

Construct a prefix for a path and a labeled strategy. The third argument is the initial term.

The steps during the parsing process: enter (or exit) a labeled sub-strategy, or a rule.

stepEnvironment :: Step a -> Environment Source

A path encodes a location in a strategy. Paths are represented as a list of integers.

prefixPaths :: Prefix a -> [Path] Source

Returns the current `Path`

.

majorPrefix :: Prefix a -> Prefix a Source

Transforms the prefix such that only major steps are kept in the remaining strategy.

isEmptyPrefix :: Prefix a -> Bool Source

# Misc

cleanUpStrategy :: (a -> a) -> LabeledStrategy a -> LabeledStrategy a Source

Use a function as do-after hook for all rules in a labeled strategy, but also use the function beforehand

cleanUpStrategyAfter :: (a -> a) -> LabeledStrategy a -> LabeledStrategy a Source

Use a function as do-after hook for all rules in a labeled strategy

rulesInStrategy :: IsStrategy f => f a -> [Rule a] Source

Returns a list of all major rules that are part of a labeled strategy