
14 Jan
2005
14 Jan
'05
4:47 a.m.
On Fri, 14 Jan 2005, Gracjan Polak wrote:
I want to implement linear list shuffle in Haskell (http://c2.com/cgi/wiki?LinearShuffle) and I invented code:
shuffle :: [a] -> IO [a] shuffle [] = return [] shuffle x = do r <- randomRIO (0::Int,length x - 1) s <- shuffle (take r x ++ drop (r+1) x) return ((x!!r) : s)
This algorithm seems not effective, length, take, drop and (!!) are costly. Is there any better way to implement shuffle?
Is it a good idea to use IO monad for this plain computation?