
M'luds, There's probably a place to report this properly, but I thought if I mentioned it here, you could throw cabbages at me and tell me where to go. Exhibit A, from http://haskell.org/ghc/docs/6.12.2/html/libraries/random-1.0.0.2/System-Rand... "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 properties: * It guarantees to succeed on any string." Exhibit B, from ghci Prelude System.Random> read "00-00-00-00-00-00" :: StdGen Loading package old-locale-1.0.0.2 ... linking ... done. Loading package time-1.1.4 ... linking ... done. Loading package random-1.0.0.2 ... linking ... done. *** Exception: Prelude.read: no parse The prosecution rests. Conor

M'luds As counsel for the defence, I would advise my learned friend to consult the source code. On 6 Oct 2010, at 21:02, Conor McBride wrote:
Exhibit A, from http://haskell.org/ghc/docs/6.12.2/html/libraries/random-1.0.0.2/System-Rand...
"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 properties:
* It guarantees to succeed on any string."
instance Read StdGen where readsPrec _p = \ r -> case try_read r of r'@[_] -> r' _ -> [stdFromString r] -- because it shouldn't ever fail. where try_read r = do (s1, r1) <- readDec (dropWhile isSpace r) (s2, r2) <- readDec (dropWhile isSpace r1) return (StdGen s1 s2, r2) {- If we cannot unravel the StdGen from a string, create one based on the string given. -} stdFromString :: String -> (StdGen, String) stdFromString s = (mkStdGen num, rest) where (cs, rest) = splitAt 6 s num = foldl (\a x -> x + 3 * a) 1 (map ord cs) This is clearly guaranteed to succeed on any String, provided you don't use big complicated words. Prelude System.Random Text.Read Numeric> read "jam" :: StdGen 1382 1 Prelude System.Random Text.Read Numeric> read "marmalade" :: StdGen *** Exception: Prelude.read: no parse At least this explains how to work around the problem. take 6 Conor

On Wednesday 06 October 2010 22:02:57, Conor McBride wrote:
M'luds,
There's probably a place to report this properly, but I thought if I mentioned it here, you could throw cabbages at me and tell me where to go.
http://hackage.haskell.org/trac/ghc/newticket?type=bug Component: libraries(other) Decide whether you regard it as a documentation bug or a wrong result at runtime. (Documentation bug seems more reasonable)
Exhibit A, from http://haskell.org/ghc/docs/6.12.2/html/libraries/random-1.0.0.2/System- Random.html
"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
^^^^ Note that that should be uppercase, Read.
following properties:
* It guarantees to succeed on any string."
It does in the sense that reads foo :: [(StdGen,[Char])] /= [] for all foo. The way it's formulated invites wrong interpretations, though.
Exhibit B, from ghci
Prelude System.Random> read "00-00-00-00-00-00" :: StdGen Loading package old-locale-1.0.0.2 ... linking ... done. Loading package time-1.1.4 ... linking ... done. Loading package random-1.0.0.2 ... linking ... done. *** Exception: Prelude.read: no parse
The prosecution rests.
Conor

Hi Daniel On 6 Oct 2010, at 21:33, Daniel Fischer wrote:
On Wednesday 06 October 2010 22:02:57, Conor McBride wrote:
tell me where to go.
http://hackage.haskell.org/trac/ghc/newticket?type=bug
Component: libraries(other)
OK, I signed up and did that.
Decide whether you regard it as a documentation bug or a wrong result at runtime.
(Documentation bug seems more reasonable)
Of the options available, yes.
Exhibit A, from http://haskell.org/ghc/docs/6.12.2/html/libraries/random-1.0.0.2/System- Random.html
"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
^^^^ Note that that should be uppercase, Read.
Never the less, the first sentence makes it clear that my expectations were in conformance with the documentation, so...
following properties:
* It guarantees to succeed on any string."
It does in the sense that
reads foo :: [(StdGen,[Char])] /= []
for all foo. The way it's formulated invites wrong interpretations, though.
...I beg to differ. The way it's formulated is clear, but not what happens. It seems that there's an unexpected tension between the use of Read for serialization (in which you want *reads* to be compositional) and the utility of making a StdGen from some sort of identifier. Perhaps the better fix is to separate the latter functionality. All the best Conor

On Wednesday 06 October 2010 23:30:54, Conor McBride wrote:
StdGen. In general, the read instance of StdGen has the
^^^^ Note that that should be uppercase, Read.
Never the less, the first sentence makes it clear that my expectations were in conformance with the documentation, so...
I just wanted to point out a typo in the docs, so you could include that in the ticket :)
All the best
ditto
Conor
Cheers, Daniel
participants (2)
-
Conor McBride
-
Daniel Fischer