cvs commit: fptools/libraries/base/GHC Read.lhs

Olaf Chitil olaf@cs.york.ac.uk
Mon, 22 Apr 2002 18:38:16 +0100


> This is most odd.  Why on earth does Haskell 98 lex
> have the equation
>         lex "" = [("","")]
> 
> rather than
>         lex "" = []
> 
> After all, "" isn't a lexeme.
> 
> What would break if I proposed to change the H98 equation?

I agree that it is odd. 

I noticed that the definitions of read and readIO rely on this
behaviour, to handle trailing white space.

read             :: (Read a) => String -> a
read s           =  case [x | (x,t) <- reads s, ("","") <- lex t] of
                         [x] -> x
                         []  -> error "Prelude.read: no parse"
                         _   -> error "Prelude.read: ambiguous parse"

readIO   :: Read a => String -> IO a
readIO s =  case [x | (x,t) <- reads s, ("","") <- lex t] of
              [x] -> return x
              []  -> ioError (userError "Prelude.readIO: no parse")
              _   -> ioError (userError "Prelude.readIO: ambiguous
parse")

We could replace `("","") <- lex t' by `all isSpace t'. I my opinion the
definitions would become clearer.

Only if the definition of `lex' where ever changed, for example to deal
with comments, then the definitions of `read' and `readIO' might have to
be changed as well.

I don't see any other problem, but maybe others do?

Olaf

-- 
OLAF CHITIL, 
 Dept. of Computer Science, The University of York, York YO10 5DD, UK. 
 URL: http://www.cs.york.ac.uk/~olaf/
 Tel: +44 1904 434756; Fax: +44 1904 432767