[Haskell-cafe] Random/StdGen/read: there is something unclear (or
me_zara at dea.spamcon.org
Tue Mar 13 04:59:29 EDT 2007
Sorry if this question is too basic, but I am trying to learn Haskell
and from tiem to time I get stuck. (And forgive me, I haev a heavy
procedural background, so functional programming is hard for me)
I am trying to use 'read' to create a random generator, applying it on
some text. As the Report, says:
# In addition, 'read' may be used to map an arbitrary string (not
# necessarily one produced by 'show') onto a value of type 'StdGen'.
# In general, the 'read' instance of 'StdGen' has the following
# * It guarantees to succeed on any string.
# * It guarantees to consume only a finite portion of the string.
# * Different argument strings are likely to result in different
But it does not succeed on "any string". Code follows
module Pepe where
pepin :: StdGen
pepin = read "cosita"
pepe :: StdGen
pepe = read "cositaLinda"
If I evaluate pepin, results are:
38273 1 :: StdGen
(360 reductions, 554 cells)
But if I evaluate pepe, all changes:
Program error: Prelude.read: no parse
(380 reductions, 694 cells)
Am I misunderstanding something, or is StdGen -> read buggy?
As you can see, I am using Hugs, version Sep 2006 to test.
TIA, best regards,
More information about the Haskell-Cafe