[Haskell-beginners] Re: permuting a list
Heinrich Apfelmus
apfelmus at quantentunnel.de
Thu Feb 12 10:11:23 EST 2009
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 at 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
More information about the Beginners
mailing list