-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Execute a set of actions (e.g. parsers) in each possible order -- -- Sequence a set of Alternative actions in each possible order, based on -- "Parsing Permutation Phrases", by Arthur Baars, Andres Loeh and S. -- Doaitse Swierstra, Haskell Workshop 2001. This is particularly -- useful for constructing a parser for permutations of elements. This -- version has a slightly different interface from the paper. @package action-permutations @version 0.0.0.0 -- | Constructing an action as a choice between all the permutations of -- some given actions (e.g. parsers), based on "Parsing Permutation -- Phrases", by Arthur Baars, Andres Loeh and S. Doaitse Swierstra, -- Haskell Workshop 2001. -- -- This version has a slightly different interface from the paper. module Control.Applicative.Permutation -- | A representation of a permutation of actions of an Alternative -- type p. The value type of the composite action is a. -- -- Permutations are constructed from the primitives atom, -- optAtom and maybeAtom, and combined using the methods of -- Functor and Applicative. They are converted back to -- composite actions using runPerms and runPermsSep. -- -- The component actions of a permutation will be executed in each -- possible order, but the values they produce are always assembled in -- the order they occur in the program text, as in the following -- permutations of one, two or three component actions: -- --
runPerms (f <$> atom a) = f -- <$> a
runPerms (f <$> atom a -- <*> atom b) = (f <$> a -- <*> b) <|> (flip f <$> b -- <*> a)
runPerms (f <$> atom a -- <*> atom b <*> atom c) = ((\ x -- (y,z) -> f x y z) <$> a <*> ((,) -- <$> b <*> c) <|> (flip -- (,) <$> c <*> b)) <|> ((\ y -- (z,x) -> f x y z) <$> b <*> ((,) -- <$> a <*> c) <|> (flip -- (,) <$> c <*> a)) <|> ((\ z -- (x,y) -> f x y z) <$> c <*> ((,) -- <$> a <*> b) <|> (flip -- (,) <$> b <*> a))