GHC's readLitChar does not conform to 98

Akim Demaille
Wed, 05 Mar 2003 14:50:11 +0100


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:

module Main (main)

import IO (stderr, hPutStrLn)
import Char (digitToInt, lexLitChar, readLitChar)

main :: IO ()
main =
    do hPutStrLn stderr (show $ readLitChar "A")
       hPutStrLn stderr (show $ readLitChar "'A'")

ghc says:

/tmp % ghc --version                                             nostromo 14:45
The Glorious Glasgow Haskell Compilation System, version 5.04.2
/tmp % /tmp/a.out                                                nostromo 14:46

and Hugs says:

/tmp % runhugs Main.hs                                           nostromo Err 1

The doc seems to agree with Hugs (thanks to sebc for the pointer):


> 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       =  "\\n" ++ s
>   lexLitChar  "\\nHello"   =  [("\\n", "Hello")]
>   readLitChar "\\nHello"   =  [('\n', "Hello")]