permutations package:parser-combinators

This module is a generalization of the package parsec-permutation authored by Samuel Hoffstaetter: https://hackage.haskell.org/package/parsec-permutation 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: https://www.cs.ox.ac.uk/jeremy.gibbons/wg21/meeting56/loeh-paper.pdf 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:
test = runPermutation $
(,,) <$> toPermutationWithDefault ""  (some (char 'a'))
<*> toPermutation (char 'b')
<*> toPermutationWithDefault '_' (char 'c')
This module specialized the interface to Monad for potential efficiency considerations, depending on the monad the permutations are run over. For a more general interface requiring only Applicative, and for more complete documentation, see the Permutations module.