
#12874: Read/Show Incompatibility in base -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * component: Compiler => libraries/base Comment: This does indeed seem to be a problem with `Proxy`'s `Read` instance. I've copied its current implementation below: {{{#!hs instance Read (Proxy s) where readsPrec d = readParen (d > 10) (\r -> [(Proxy, s) | ("Proxy",s) <- lex r ]) }}} That `readParen (d > 10)` is a problem, since if the precendence `d` is greater than 10, then in order for parsing to succeed, `"Proxy"` must be surrounded by at least one set of parentheses. But, as you noted, this is too stringent of a requirement, since `show (Thing Proxy)` yields `"Thing Proxy"`, without any parentheses. One way to fix this is to ignore the precedence: {{{#!hs instance Read (Proxy s) where readsPrec _ = readParen False (\r -> [(Proxy, s) | ("Proxy",s) <- lex r ]) }}} Then `"Thing Proxy"`, `"Thing (Proxy)"`, etc. all parse. But then again, this definition is basically equivalent to what `deriving Read` produces. Why not use that? FWIW, `Proxy` isn't the only type to suffer from this problem. It looks like `Coercion`, `:~:`, `:~~:`, and `U1` also have `Read` instances with the same issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12874#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler