
12 Feb
2009
12 Feb
'09
10:11 a.m.
Patrick LeBoutillier wrote:
permute :: [a] -> [[a]] permute xs = [s:ps | (s,ss) <- select xs, ps <- permute ss]
select :: [a] -> [(a,[a])] select [] = [] select (x:xs) = (x,xs) : [(s,x:ss) | (s,ss) <- select xs]
When I run this in ghci I always get an empty list:
[patrickl@fc9i386 haskell]$ ghci permute.hs GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. [1 of 1] Compiling Main ( permute.hs, interpreted ) Ok, modules loaded: Main. *Main> permute [1,2,3] []
Am i missing something?
No. The base case permute [] = [[]] was missing. Regards, apfelmus -- http://apfelmus.nfshost.com