Partial fix for Trac #4136
authorsimonpj@microsoft.com <unknown>
Wed, 7 Jul 2010 13:57:25 +0000 (13:57 +0000)
committersimonpj@microsoft.com <unknown>
Wed, 7 Jul 2010 13:57:25 +0000 (13:57 +0000)
In 'choose' (which is a library function designed specifically
to support derived instances of Read), we must match Symbol
as well as Ident, for nullary constructors that (wierdly) are
symbols.

GHC/Read.lhs

index f99e2df..b568287 100644 (file)
@@ -314,10 +314,15 @@ choose :: [(String, ReadPrec a)] -> ReadPrec a
 -- ^ Parse the specified lexeme and continue as specified.
 -- Esp useful for nullary constructors; e.g.
 --    @choose [(\"A\", return A), (\"B\", return B)]@
+-- We match both Ident and Symbol because the constructor
+-- might be an operator eg (:=:)
 choose sps = foldr ((+++) . try_one) pfail sps
            where
-             try_one (s,p) = do { L.Ident s' <- lexP ;
-                                  if s == s' then p else pfail }
+             try_one (s,p) = do { token <- lexP ;
+                                  case token of
+                                    L.Ident s'  | s==s' -> p
+                                    L.Symbol s' | s==s' -> p
+                                    _other              -> pfail }
 \end{code}