Constructing mutable permutations

Construct a permutation from a list of elements.
newListPermute n is creates a permutation of size n with
the ith element equal to is !! i. For the permutation to be valid,
the list is must have length n and contain the indices 0..(n-1)
exactly once each.

Construct a permutation from a list of swaps.
newSwapsPermute n ss creates a permutation of size n given a
sequence of swaps.
If ss is [(i0,j0), (i1,j1), ..., (ik,jk)], the
sequence of swaps is
i0 <-> j0, then
i1 <-> j1, and so on until
ik <-> jk.

Advance a permutation to the next permutation in lexicogrphic order and
return True. If no further permutaitons are available, return False and
leave the permutation unmodified. Starting with the idendity permutation
and repeatedly calling setNext will iterate through all permutations of a
given size.

Applying permutations

Get a lazy list of swaps equivalent to the permutation. A result of
[ (i0,j0), (i1,j1), ..., (ik,jk) ] means swap i0 <-> j0,
then i1 <-> j1, and so on until ik <-> jk. The laziness makes this
function slightly dangerous if you are modifying the permutation.

Sorting

getSort n xs sorts the first n elements of xs and returns a
permutation which transforms xs into sorted order. The results are
undefined if n is greater than the length of xs. This is a special
case of getSortBy.

getOrder n xs returns a permutation which rearranges the first n
elements of xs into ascending order. The results are undefined if n is
greater than the length of xs. This is a special case of getOrderBy.

getRank n xs eturns a permutation, the inverse of which rearranges the
first n elements of xs into ascending order. The returned permutation,
p, has the property that p[i] is the rank of the ith element of xs.
The results are undefined if n is greater than the length of xs.
This is a special case of getRankBy.