
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=1989#a1990 Is the algorithm wrong ar am I using it wrong? Also, is the second argument to shuffle supposed to eb random numbers, ie the function should be used in the IO Monad?

On Mon, 02 Mar 2009 15:18:17 +0100, friggin friggin
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=1989#a1990
Is the algorithm wrong ar am I using it wrong?
The second parameter of extractTree is of type Tree a, you didn't suply a line specifying what to do with the value (Leaf a), so you didn't cover all possibilities of this type; that's why you get the message "Non-exhaustive patterns in function extractTree".
Also, is the second argument to shuffle supposed to eb random numbers, ie the function should be used in the IO Monad?
If you supply a prefabricated random list of Integers, this function can be pure (i.e. not in the IO monad) -- Met vriendelijke groet, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ --

Am Montag, 2. März 2009 15:18 schrieb friggin friggin:
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=1989#a1990
Is the algorithm wrong ar am I using it wrong?
a) what if there are more random numbers than elements in the tree? I suggest 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 to extractTree
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.

On 2009 Mar 2, at 9:18, friggin friggin wrote:
Also, is the second argument to shuffle supposed to eb random numbers, ie the function should be used in the IO Monad?
If you want random numbers you will usually fmap this function over a list of random numbers generated in IO, thus isolating the pure algorithm from the impure generation. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (4)
-
Brandon S. Allbery KF8NH
-
Daniel Fischer
-
friggin friggin
-
Henk-Jan van Tuyl