permutations

The permutations function returns the list of all permutations of the argument. Note that the order of permutations is not lexicographic. It satisfies the following property:
map (take n) (take (product [1..n]) (permutations ([1..n] ++ undefined))) == permutations [1..n]

Laziness

The permutations function is maximally lazy: for each n, the value of permutations xs starts with those permutations that permute take n xs and keep drop n xs.

Examples

>>> permutations "abc"
["abc","bac","cba","bca","cab","acb"]
>>> permutations [1, 2]
[[1,2],[2,1]]
>>> permutations []
[[]]
This function is productive on infinite inputs:
>>> take 6 $ map (take 3) $ permutations ['a'..]
["abc","bac","cba","bca","cab","acb"]
The permutations function returns the list of all permutations of the argument.
The permutations function returns the list of all permutations of the argument. Since: 4.20.0.0
The permutations function returns the list of all permutations of the argument.
>>> permutations "abc"
["abc","bac","cba","bca","cab","acb"]
The permutations function is maximally lazy: for each n, the value of permutations xs starts with those permutations that permute take n xs and keep drop n xs. This function is productive on infinite inputs:
>>> take 6 $ map (take 3) $ permutations ['a'..]
["abc","bac","cba","bca","cab","acb"]
Note that the order of permutations is not lexicographic. It satisfies the following property:
map (take n) (take (product [1..n]) (permutations ([1..n] ++ undefined))) == permutations [1..n]
The permutations function returns the list of all permutations of the argument.
>>> permutations "abc"
["abc","bac","cba","bca","cab","acb"]
permutations returns a list of all permutations of the argument.
> permutations "abc"
["abc","bac","cba","bca","cab","acb"]
Generate an infinite list of all finite (such that only finite number of elements change their positions) permutations of the argument.
>>> take 6 (fmap (take 3) (permutations (0...)))
[[0,1,2],[1,0,2],[2,1,0],[1,2,0],[2,0,1],[0,2,1]]
Not on Stackage, so not searched. Permutations of finite sets
O(n!). Returns the list of all permutations of the argument.
>>> permutations mempty
Slist {sList = [Slist {sList = [], sSize = Size 0}], sSize = Size 1}

>>> permutations $ slist "abc"
Slist {sList = [Slist {sList = "abc", sSize = Size 3},Slist {sList = "bac", sSize = Size 3},Slist {sList = "cba", sSize = Size 3},Slist {sList = "bca", sSize = Size 3},Slist {sList = "cab", sSize = Size 3},Slist {sList = "acb", sSize = Size 3}], sSize = Size 6}
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.
permutations1 operates like permutations, but uses the knowledge that its input is non-empty to produce output where every element is non-empty.
permutations1 = fmap fromList . permutations . toList
permutations1 operates like permutations, but uses the knowledge that its input is non-empty to produce output where every element is non-empty.
permutations1 = fmap fromList . permutations . toList
Since: 4.20.0.0
Takes a list and returns a sorted list using Permutationsort algorithm

Examples

>>> permutationsort ([16, 23, 4, 8, 15, 42] :: [Int])
[4,8,15,16,23,42]
>>> permutationsort ([(1, 16), (5, 23), (2, 4) ,(3, 8), (0, 15) , (4, 42)] :: [(Int, Int)])
[(0,15),(1,16),(2,4),(3,8),(4,42),(5,23)]
Permutations and universal set functions for the phonetic-languages series and phladiprelio of packages (AFTOVolio-related). This module uses no vectors, but instead uses arrays.
Special permutations functions for the phonetic-languages and phladiprelio series of packages. This module uses no vectors, but instead uses arrays.
Special permutations functions for the phonetic-languages and phladiprelio series of packages. This module uses no vectors, but instead uses arrays.
Special permutations functions for the AFTOVolio. This module uses no vectors, but instead uses arrays.
Permutations data type to mark the needed permutations type from the other modules.
This module provides the permutationsort function for sorting lists