
Hi! 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) where 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 [] [('A',"")] and Hugs says: /tmp % runhugs Main.hs nostromo Err 1 [('A',"")] [('\'',"A'")] The doc seems to agree with Hugs (thanks to sebc for the pointer): http://www.haskell.org/onlinereport/char.html
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")]