Error in Haskell 98 Report 'lex' function

Ah yes, this is a genuine bug. Haskell 98 changed at some point to allow identifiers and field labels with a leading '_', but the library didn't keep pace. I'll fix GHC. HOWEVER, the sad thing is that the same bug is in the Haskell 98 Report itself, now begin printed. The definition of lex is wrong. Ah well, I knew this would happen. I'd better start keeping a new bug list! Simon -----Original Message----- From: Jong Keun Na [mailto:jongkn@microsoft.com] Sent: 10 February 2003 02:48 To: Simon Peyton-Jones; haskell-cafe@haskell.org Subject: RE: Auto generated instance codes through 'deriving' The following code snippet not works correctly.
data Obj = Obj {_id, p1, p2::Int} deriving (Show, Read)
showObj :: Obj -> String
showObj o = show o
main = do print (showObj (read "Obj {_id=1,p1=10,p2=20}"))
return ()
The reason is because I used the property name with underscore char like "_id". Looking into auto generated class codes and seeing they show it should encompass identifiers with special characters with parenthesis, so I tried "Obj {(_id)=1,p1=10,p2=20}" as argument of read func. But, the result is same, parse error. Is this problem by-design or bug? Or Am I missing any point? Thanks, /JongKeun -----Original Message----- From: Simon Peyton-Jones Sent: Friday, February 07, 2003 5:41 PM To: Jong Keun Na; haskell-cafe@haskell.org Subject: RE: Auto generated instance codes through 'deriving' Try -ddump-deriv http://haskell.cs.yale.edu/ghc/docs/latest/html/users_guide/options-debu gging.html#DUMPING-OUTPUT Simon -----Original Message----- From: Jong Keun Na [mailto:jongkn@microsoft.com] Sent: 07 February 2003 06:15 To: haskell-cafe@haskell.org Subject: Auto generated instance codes through 'deriving' Hello folks, Is there any method with which I can see instance's codes generated automatically by using 'deriving' keyword in GHC? I'm curious in how GHC generates 'Read' class's instance code for user-defined data type. Any help will be great appreciated. /JongKeun

"Simon Peyton-Jones"
Ah yes, this is a genuine bug. Haskell 98 changed at some point to allow identifiers and field labels with a leading '_', but the library didn't keep pace.
I believe the fix for 'lex' is something like the following. Regards, Malcolm diff -u -r1.5 Lex.hs --- src/prelude/PreludeText/Lex.hs 2001/11/09 17:19:06 1.5 +++ src/prelude/PreludeText/Lex.hs 2003/02/10 12:30:00 @@ -26,13 +26,14 @@ lex (c:s) | isSingle c = [([c],s)] | isSym c = [(c:sym,t) | (sym,t) <- [span isSym s]] - | isAlpha c = [(c:nam,t) | (nam,t) <- [span isIdChar s]] + | isIdInit c = [(c:nam,t) | (nam,t) <- [span isIdChar s]] | isDigit c = [(c:ds++fe,t) | (ds,s) <- [span isDigit s], (fe,t) <- lexFracExp s ] | otherwise = [] -- bad character where - isSingle c = c `elem` ",;()[]{}_`" + isSingle c = c `elem` ",;()[]{}`" isSym c = c `elem` "!@#$%&*+./<=>?\\^|:-~" + isIdInit c = isAlpha c || c == '_' isIdChar c = isAlphaNum c || c `elem` "_'" lexFracExp ('.':c:s) | isDigit c

Speaking of changes, how hard would it be to allow the last element in a list to have a comma at the end? [ 1, 2, -- this is illegal ] I'm accustomed to the 'extra comma' syntax in Python. I like it because it then seems to be easier to add new items, and easier to read/write lists in a text file. -- Shae Matijs Erisson - 2 days older than RFC0226 #haskell on irc.freenode.net - We Put the Funk in Funktion
participants (3)
-
Malcolm Wallace
-
Shae Matijs Erisson
-
Simon Peyton-Jones