[GHC] #12874: Read/Show Incompatibility in base

#12874: Read/Show Incompatibility in base -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I just stumbled across a situation where the deriving machinery, in combination with types provided by base, produces Show/Read instances that are incompatible. Here is a minimal example: {{{#!hs import Data.Proxy main :: IO () main = do x <- readLn print (x :: Thing (Proxy Int)) data Thing a = Thing a deriving (Read,Show) }}} If you run this program and type "Thing Proxy" into standard in, you get a parse error. If you type in "Thing (Proxy)", it works fine. Calling `show` on `Thing Proxy` gives the string "Thing Proxy" though. So, `read . show =/= id` in this case. This might just be an issue with `Proxy`'s Read instance, but I'm not really sure. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12874 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#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

#12874: Read/Show Incompatibility in base -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: patch 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): Phab:D3871 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D3871 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12874#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12874: Read/Show Incompatibility in base
-------------------------------------+-------------------------------------
Reporter: andrewthad | Owner: (none)
Type: bug | Status: patch
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): Phab:D3871
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ryan Scott

#12874: Read/Show Incompatibility in base -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: libraries/base | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | libraries/base/tests/T12874 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3871 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: patch => closed * testcase: => libraries/base/tests/T12874 * resolution: => fixed * milestone: => 8.4.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12874#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC