[GHC] #11628: Unexpected results with Read/Show

GHC ghc-devs at haskell.org
Mon Feb 22 21:26:49 UTC 2016


#11628: Unexpected results with Read/Show
-------------------------------------+-------------------------------------
        Reporter:  crockeea          |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.10.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by crockeea):

 Replying to [comment:2 rwbarton]:
 > Lots of distractions here. Here is the crux of the matter:
 > {{{
 > newtype X u = X u
 > instance Show u => Show (X u) where show (X u) = show u
 > main = print (Just (X (Just 1)))   -- prints "Just Just 1"
 > }}}
 > Of course, you should just define `showsPrec` like you mentioned.
 >
 > Just defining `show` should be okay if (either you don't care about
 compatibility with Read or) the output is a single token, like a number or
 a quoted string. Otherwise you need to define `showsPrec`. Agree that the
 docs should be clearer on this point.

 Thanks for clarifying. So it seems like this is just a documentation
 problem.

 For SPJ or future visitors: the problem as I see it is that the second
 print statement results in a runtime exception (`Prelude.read: no parse`).
 I believe it should run without exception. Apparently, based on my `Show`
 instances, this is non unexpected behavior. However, the documentation for
 show/read doesn't make it clear that I should define `showsPrec` rather
 than `show`.

 Given that rwbarton thinks the behavior is expected, then this ticket is
 about updated the documentation for Text.Read and Text.Show.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11628#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list