[Haskell-cafe] On the purity of Haskell /Random generators
Steve Horne
sh006d3592 at blueyonder.co.uk
Fri Dec 30 02:26:08 CET 2011
On 30/12/2011 00:22, Jerzy Karczmarczuk wrote:
> Steve Horne :
>> Some code (intended to be loaded into GHCi and played with)
>>
>> -- import System.Random
>> -- randSelect "this is a list" 5 (mkStdGen 9877087)
>> -- ...
>> module P23 (randSelect) where
>> -- ...
>> randSelect' (x:xs) n l g = let xsLen = (l - 1)
>> (rnd, g') = randomR (0, xsLen) g
>> -- ...
>>
>> I see no IO monad anywhere in there. Of course I'm cheating -
>> providing a constant seed at runtime.
>
> The last remark is irrelevant. Normally the seed IS constant, injected
> once, then updated by the generator iself.
>
> I don't know what you are trying to prove.
I don't know why you think I'm trying to prove something here.
Earlier, I mentioned that Haskell provides pure functional random number
support in the library - as part of going off on a tangent and, as it
happens, of making a mistake. I specifically said something like "with
no mention of the IO monad" with respect to type signatures.
You said "Look well at those functions, please". I accepted your
challenge. I looked well. I still say that Haskell provides pure
functional random number support in the library.
My "last remark" was there basically because of the earlier mistake -
acknowledging that I've bypassed the whole issue of where the seed comes
from, which may for all I know be supported by a library IO action, and
which would be relevant given how this randomness thread started. That
was my first mistake in this randomness thread - another mistake I made
was saying unsafePerformIO might reasonably be used to sneak in entropy.
Basically, I replied to your challenge - nothing more. I really don't
even care much about random numbers - that's why my easiest reference
was from back when I was doing those tutorials. There is no deep point
here unless you're making one I haven't understood yet.
As for whether or not Haskell is pure - this randomness thread isn't
relevant to that any more.
If you see my reference to purity as a weasel way of insinuating that
there's also impurity in Haskell - I don't need to insinuate that, I've
openly stated my view and explained my reasoning as well as I'm able.
What point is there in being a cowardly weasel if you also paint a
bullseye on your head and shout "Here I am!"?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111230/78fdd143/attachment.htm>
More information about the Haskell-Cafe
mailing list