[GHC] #9240: "read . show ≡ id" not satisfied by Data.Fixed
#9240: "read . show ≡ id" not satisfied by Data.Fixed ------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: libraries/base | Version: 7.2.1 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9213 | ------------------------------------+------------------------------------- As pointed out in #9213, the desired property "read . show ≡ id" is not satisfied for all resolutions. For instance, consider the following example: {{{
data B7 instance HasResolution B7 where resolution _ = 128
1.070 :: Fixed B7 1.062 1.062 :: Fixed B7 1.054
read "1.070" :: Fixed B7 1.062 read "1.062" :: Fixed B7 1.054 }}}
This behaviour can be reproduced all the way back to GHC 7.2.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9240> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9240: "read . show ≡ id" not satisfied by Data.Fixed -------------------------------------+------------------------------------ Reporter: hvr | Owner: Type: bug | Status: new Priority: normal | Milestone: 7.10.1 Component: libraries/base | Version: 7.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #9231 -------------------------------------+------------------------------------ Changes (by hvr): * related: #9213 => #9231 Old description:
As pointed out in #9213, the desired property "read . show ≡ id" is not satisfied for all resolutions. For instance, consider the following example:
{{{
data B7 instance HasResolution B7 where resolution _ = 128
1.070 :: Fixed B7 1.062 1.062 :: Fixed B7 1.054
read "1.070" :: Fixed B7 1.062 read "1.062" :: Fixed B7 1.054 }}}
This behaviour can be reproduced all the way back to GHC 7.2.1
New description: As pointed out in #9231, the desired property "read . show ≡ id" is not satisfied for all resolutions. For instance, consider the following example: {{{#!hs
data B7 instance HasResolution B7 where resolution _ = 128
1.070 :: Fixed B7 1.062 1.062 :: Fixed B7 1.054
read "1.070" :: Fixed B7 1.062 read "1.062" :: Fixed B7 1.054 }}}
This behaviour can be reproduced all the way back to GHC 7.2.1 -- -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9240#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9240: "read . show ≡ id" not satisfied by Data.Fixed -------------------------------------+------------------------------------- Reporter: hvr | Owner: ekmett Type: bug | Status: patch Priority: normal | Milestone: 7.10.1 Component: Core | Version: 7.2.1 Libraries | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: #9231 None/Unknown | Test Case: | Blocking: | Differential Revisions: Phab:D547 | -------------------------------------+------------------------------------- Changes (by thomie): * cc: core-libraries-committee@… (added) * status: new => patch * differential: => Phab:D547 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9240#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9240: "read . show ≡ id" not satisfied by Data.Fixed -------------------------------------+------------------------------------- Reporter: hvr | Owner: ekmett Type: bug | Status: patch Priority: normal | Milestone: 7.10.1 Component: Core | Version: 7.2.1 Libraries | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: #9231 None/Unknown | Test Case: | Blocking: | Differential Revisions: Phab:D547 | -------------------------------------+------------------------------------- Comment (by Herbert Valerio Riedel <hvr@…>): In [changeset:"7c38e985aa211ca44039c6d1db9fa13690749c59/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="7c38e985aa211ca44039c6d1db9fa13690749c59" Make `read . show = id` for Data.Fixed (fix #9240) The QuickCheck property now succeeds: prop :: Fixed B7 -> Bool prop a = read (show a) == a This changes the Show instance for Fixed to round up, rather than down when calculating a digit. This needs to happen because Read also rounds down: data B7 instance HasResolution B7 where resolution _ = 128 1 / 128 = 0.0078125 read "0.007" = (0.000 :: Fixed B7) Here is an example of the change to Show: showFixed False (0.009 :: Fixed B7) -- Broken: "0.007" -- Fixed: "0.008" And now Read can continue to round down: read "0.008" = (0.0078125 :: Fixed B7) Reviewed By: hvr, ekmett Differential Revision: https://phabricator.haskell.org/D547 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9240#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9240: "read . show ≡ id" not satisfied by Data.Fixed -------------------------------------+------------------------------------- Reporter: hvr | Owner: ekmett Type: bug | Status: closed Priority: normal | Milestone: 7.10.1 Component: Core | Version: 7.2.1 Libraries | Keywords: Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: | Related Tickets: #9231 None/Unknown | Test Case: | Blocking: | Differential Revisions: Phab:D547 | -------------------------------------+------------------------------------- Changes (by hvr): * status: patch => closed * resolution: => fixed -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9240#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC