cvs commit: fptools/libraries/base/GHC Read.lhs
Simon Peyton-Jones
simonpj@microsoft.com
Tue, 23 Apr 2002 00:56:45 -0700
Ah yes, that's it. The client of 'lex' may want to be able to
distinguish
"end-of-string" from "illegal lexeme", so that he can check that
the remainder of the string is just Haskell white space.
So I'll add a comment to the H98 report code, but leave it as is.
What do we need for the new lexer? I think we want a new lexeme,
EOF:
data Lexeme =3D EOF | Char Char | String String | ...
So now we can lex an EOF lexeme (repeatedly if we want)
rather than failing.
Koen: does that make sense to you? Could you implement it?
(In the real code, of course.) Then we could fix up the grevious
hack in the implementation of 'lex' that Sven had to put in.
Simon
| -----Original Message-----
| From: Olaf Chitil [mailto:olaf@cs.york.ac.uk]=20
| Sent: 22 April 2002 18:38
| To: Simon Peyton-Jones
| Cc: Sven Panne; cvs-libraries@haskell.org; Koen Claessen=20
| (Koen Claessen); sof@galois.com;=20
| Malcolm.Wallace@cs.york.ac.uk; Olaf.Chitil@cs.york.ac.uk
| Subject: Re: cvs commit: fptools/libraries/base/GHC Read.lhs
|=20
|=20
|=20
| > This is most odd. Why on earth does Haskell 98 lex
| > have the equation
| > lex "" =3D [("","")]
| >=20
| > rather than
| > lex "" =3D []
| >=20
| > After all, "" isn't a lexeme.
| >=20
| > What would break if I proposed to change the H98 equation?
|=20
| I agree that it is odd.=20
|=20
| I noticed that the definitions of read and readIO rely on=20
| this behaviour, to handle trailing white space.
|=20
| read :: (Read a) =3D> String -> a
| read s =3D case [x | (x,t) <- reads s, ("","") <- lex t] of
| [x] -> x
| [] -> error "Prelude.read: no parse"
| _ -> error "Prelude.read: ambiguous parse"
|=20
| readIO :: Read a =3D> String -> IO a
| readIO s =3D case [x | (x,t) <- reads s, ("","") <- lex t] of
| [x] -> return x
| [] -> ioError (userError "Prelude.readIO: no parse")
| _ -> ioError (userError "Prelude.readIO: ambiguous
| parse")
|=20
| We could replace `("","") <- lex t' by `all isSpace t'. I my=20
| opinion the definitions would become clearer.
|=20
| Only if the definition of `lex' where ever changed, for=20
| example to deal with comments, then the definitions of `read'=20
| and `readIO' might have to be changed as well.
|=20
| I don't see any other problem, but maybe others do?
|=20
| Olaf
|=20
| --=20
| OLAF CHITIL,=20
| Dept. of Computer Science, The University of York, York YO10=20
| 5DD, UK.=20
| URL: http://www.cs.york.ac.uk/~olaf/
| Tel: +44 1904 434756; Fax: +44 1904 432767
|=20