on master help sign in
Implenting Data.List.Permutations
commitfd5baaa205e9ee5959b1c71e9c5f57ebab0e5bfc authorAverage-user <lucaspolymeris@gmail.com> dateWed 29 Nov 2017, 22:51 (9 years ago) parent421f138
1 file changed+10
libs/contrib/Data/List/Permutations.idr+10
libs/contrib/Data/List/Permutations.idrnew file+10
@@ -0,0 +1,10 @@
1+module Permutations
2+
3+-- | All permutations of a list.
4+permutations : List a -> List (List a)
5+permutations [] = [[]]
6+permutations xs = [y :: zs | (y, ys) <- select xs, zs <- permutations ys]
7+ where
8+ select : List a -> List (a, List a)
9+ select [] = []
10+ select (x :: xs) = (x, xs) :: [(y, x::ys) | (y,ys) <- select xs]