in reply to Re: Functional shuffle
in thread Functional shuffle

Isn't it the case that random number generators do not entirely fit into the "pure functional" programming paradigm? I seem to recall reading somewhere that obtaining random numbers in Haskell involves the use of Monads, which is a kind of stretching of the concept of pure functional programming (maybe this is why I have never been able to really understand Monads?)...

This leads me to think that pure functional progamming is not the best way to attack the list shuffle problem...

rg0now

Replies are listed 'Best First'.
Re^3: Functional shuffle
by tall_man (Parson) on Apr 02, 2005 at 16:19 UTC
    Indeed a "functional shuffle" is a contradiction in terms. In functional programming, if you give a function the same inputs you must get the same outputs. Rand is resetting a seed somewhere, which is a disallowed side-effect in a pure functional program. However, one could define a shuffle that took a list of random numbers from some outside source as an input. The paper referenced by the OP does this.
Re^3: Functional shuffle
by tlm (Prior) on Apr 02, 2005 at 16:19 UTC

    You may very well be right. I did notice that in the article that Roy Johnson linked on the Haskell implementation the author spent longer than I would have expected on the discussion of the random numbers, which gave me the impression that the generation of random numbers has a conceptually different place, or different standing if you will, in the Haskell world than I'm used to from other programming languages.

    But to be honest, I barely understand what this requirement that the shuffle be "functional" is, as is probably plainly obvious from my various stabs at it.

    the lowliest monk