[Haskell-cafe] System.Random.Shuffle fix

friggin friggin frigginfriggins at gmail.com
Mon Mar 23 13:10:37 EDT 2009


I was looking for a shuffling algorithm to shuffle mp3-playlists so was very
happy to see System.Random.Shuffle:
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/random-shuffle-0.0.2

However I get  errors,non-exhaustive patterns in function shufleTree or
extractTree depending how I call it. Errors are at the bottom.

I fixed it but I don't have the math skills to see if I perhaps broke it
statistically ...

Here is my fix, someone (don't remember who, helped me a little):
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2789#a2789
the shuffle at the end is with the fix.


*Freet> S.shuffle [1..10] [1..3]
Loading package syb ... linking ... done.
Loading package base-3.0.3.0 ... linking ... done.
Loading package old-locale-1.0.0.1 ... linking ... done.
Loading package old-time-1.0.0.1 ... linking ... done.
Loading package random-1.0.0.1 ... linking ... done.
Loading package random-shuffle-0.0.2 ... linking ... done.
[2,4,6*** Exception: src\System\Random\Shuffle.hs:(52,6)-(55,30):
Non-exhaustive patterns in function shuffleTree

*Freet> S.shuffle [1..3] [1..10]
[2,*** Exception: src\System\Random\Shuffle.hs:(66,6)-(79,27):
Non-exhaustive patterns in function extractTree

*Freet> :load "c:/ghc/ghc-6.10.1/progs/Mp3Player/Shuffle.hs"
[1 of 1] Compiling Shuffle          (
C:\ghc\ghc-6.10.1\progs\Mp3Player\Shuffle.hs, interpreted )
Ok, modules loaded: Shuffle.
*Shuffle> shuffle [1..3] [1..10]
[2,1,3]
*Shuffle> shuffle [1..10] [1..3]
[2,4,6*** Exception:
C:\ghc\ghc-6.10.1\progs\Mp3Player\Shuffle.hs:(27,13)-(31,30): Non-exhaustive
patterns in function shuffle'

*Shuffle> shuffle [1..10] [1..10]
[2,4,6,8,10,3,9,7,5,1]
*Shuffle>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090323/e41a94c8/attachment.htm


More information about the Haskell-Cafe mailing list