[Haskell-cafe] shuffle error
daniel.is.fischer at web.de
Mon Mar 2 10:29:31 EST 2009
Am Montag, 2. März 2009 15:18 schrieb friggin friggin:
> Is the algorithm wrong ar am I using it wrong?
a) what if there are more random numbers than elements in the tree?
shuffle' (Leaf e) _ = [e]
b) You don't cater for the case when the number of the element to be extracted
is larger than the size of the tree-1
I suggest giving a first case of
extractTree n t@(Node c _ _)
| c <= n = extractTree (n `mod` c) t
> Also, is the second argument to shuffle supposed to eb random numbers, ie
> the function should be used in the IO Monad?
The function is pure. Whether you use it in the IO monad or not depends on
whether the input lives inside the IO monad.
More information about the Haskell-Cafe