I'm reading Simon Thompson's Haskell: The Craft of Functional Programming, and I'm wondering how does this work:
perms [] = [[]]
perms xs = [ x:ps | x <- xs , ps <- perms ( xs\\[x] ) ]
I can't seem to grasp how that perms( xs\\[x] )
is supposed to function. The trace of a two element list 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
?