I am reading Simon Thompson Haskell: The Craft of Functional Programming, and I wonder how this works:
perms [] = [[]] perms xs = [ x:ps | x <- xs , ps <- perms ( xs\\[x] ) ]
I cannot understand how perms( xs\\[x] ) . Tracing a list of two items shows:
perms [2,3] [ x:ps | x <- [2,3] , ps <- perms ( [2,3] \\ [x] ) ] exe.1 [ 2:ps | ps <- perms [3] ] ++ [ 3:ps | ps <- perms [2] ] exe.2 ...
How do you go from exe.1 to exe.2 ?
haskell list-comprehension permutation
Evan carroll
source share