Download Tom Manual - GForge
Transcript
Chapter 3 Strategies 3.1 3.1.1 Introduction to strategies Elementary strategy There exists three kinds of elementary strategy: Fail, which always fails, Identity, which always succeeds, and transformation rules of the form l → r. Therefore, if we consider the elementary strategy a ⇒b (which replaces a by b), we have the following results: (a -> b)[a] (a -> b)[b] (a -> b)[f(a)] (Identity)[a] (Identity)[b] (Identity)[f(a)] (Fail)[a] 3.1.2 = = = = = = = b failure failure a b f(a) failure Basic combinators Composition The sequential operator, Sequence(S1,S2), applies the strategy S1, and then the strategy S2. It fails if either S1 fails, or S2 fails. (Sequence(a -> b, b -> c))[a] = c (Sequence(a -> b, c -> d))[a] = failure (Sequence(b -> c, a -> b))[a] = failure Choice The choice operator, Choice(S1,S2), applies the strategy S1. If the application S1 fails, it applies the strategy S2. Therefore, Choice(S1,S2) fails if both S1 and S2 fail. (Choice(a (Choice(b (Choice(b (Choice(b -> -> -> -> b, c, c, c, b -> c))[a] a -> b))[a] c -> d))[a] Identity))[a] = = = = b b failure a Not The strategy Not(S), applies the strategy and fails when S succeeds. Otherwise, it succeeds and corresponds to the Identity. (Not(a -> b))[a] (Not(b -> c))[a] = failure = a 21