Error in Haskell 98 Report 'lex' function

Malcolm Wallace Malcolm.Wallace@cs.york.ac.uk
Mon, 10 Feb 2003 12:33:09 +0000


"Simon Peyton-Jones" <simonpj@microsoft.com> writes:

> 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