GHC's readLitChar does not conform to 98

Simon Peyton-Jones simonpj@microsoft.com
Tue, 1 Apr 2003 17:42:19 +0100


Excellent point, thank you.  A bogon. Fixed in the HEAD, and a
regression test added

Simon

| -----Original Message-----
| From: Akim Demaille [mailto:akim@epita.fr]
| Sent: 05 March 2003 13:50
| To: glasgow-haskell-users@haskell.org
|=20
| Hi!
|=20
| I believe the implementation of readLitChar (and lexLitChar) does not
| conform to the documentation, and this results in GHC and Hugs
| disagreeing on the following code:
|=20
| ----------------------------------------
| module Main (main)
| where
|=20
| import IO (stderr, hPutStrLn)
| import Char (digitToInt, lexLitChar, readLitChar)
|=20
| main :: IO ()
| main =3D
|     do hPutStrLn stderr (show $ readLitChar "A")
|        hPutStrLn stderr (show $ readLitChar "'A'")
| ----------------------------------------
|=20
| ghc says:
|=20
| /tmp % ghc --version
nostromo 14:45
| The Glorious Glasgow Haskell Compilation System, version 5.04.2
| /tmp % /tmp/a.out
nostromo 14:46
| []
| [('A',"")]
|=20
|=20
| and Hugs says:
|=20
| /tmp % runhugs Main.hs
nostromo Err 1
| [('A',"")]
| [('\'',"A'")]
|=20
|=20
| The doc seems to agree with Hugs (thanks to sebc for the pointer):
|=20
| <http://www.haskell.org/onlinereport/char.html>
|=20
| > The function showLitChar converts a character to a string using only
| > printable characters, using Haskell source-language escape
| > conventions. The function lexLitChar does the reverse, returning the
| > sequence of characters that encode the character. The function
| > readLitChar does the same, but in addition converts the to the
| > character that it encodes. For example:
| >
| >   showLitChar '\n' s       =3D  "\\n" ++ s
| >   lexLitChar  "\\nHello"   =3D  [("\\n", "Hello")]
| >   readLitChar "\\nHello"   =3D  [('\n', "Hello")]
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users@haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users