This module also takes inspiration from the algorithm is described in:
Parsing Permutation Phrases, by Arthur Baars, Andres Löh and Doaitse
Swierstra. Published as a functional pearl at the Haskell Workshop 2001:
From these two works we derive a flexible and general method for parsing
permutations over an Applicative structure. Quite useful in conjunction
with "Free" constructions of Applicatives, Monads, etc.
Other permutation parsing libraries tend towards using special "almost
applicative" combinators for construction which denies the library user
the ability to lift and unlift permutation parsing into any Applicative
computational context. We redefine these combinators as convenience
operators here alongside the equivalent Applicative instance.
For example, suppose we want to parse a permutation of: an optional
string of a's, the character b and an optional c. Using a standard
parsing library combinator char (e.g. ReadP)
this can be described using the Applicative instance by:
"Unlifts" a permutation parser into a parser to be evaluated with an
intercalated effect. Useful for separators between permutation elements.
For example, suppose that similar to above we want to parse a permutation
of: an optional string of a's, the character b and an optional c.
However, we also want each element of the permutation to be separated
by a colon. Using a standard parsing library combinator char, this can
be described using the Applicative instance by: