[Haskell-beginners] permuting a list

Patrick LeBoutillier patrick.leboutillier at gmail.com
Thu Feb 12 09:53:43 EST 2009


Hi,

>
> Why not keep things simple and just write a pure function?
>
> 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?

Patrick

>
> Bob
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada


More information about the Beginners mailing list