[GHC] #10011: The Data instance for Ratio violates internal invariants.

GHC ghc-devs at haskell.org
Mon Feb 23 17:38:55 UTC 2015


#10011: The Data instance for Ratio violates internal invariants.
-------------------------------------+-------------------------------------
        Reporter:  ekmett            |                   Owner:
            Type:  bug               |                  Status:  new
        Priority:  normal            |               Milestone:  7.10.1
       Component:  Core Libraries    |                 Version:  7.10.1-rc1
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:  Phab:D625
-------------------------------------+-------------------------------------

Comment (by ekmett):

 Basically (==) on Ratio rightfully assumes that the rational is already in
 lowest terms, and just compares values.

 {{{
 >>> 2 % 4
 1 % 2
 }}}

 The test there sneaks into (1 % 2) with the old illegal Data instance and
 turns it into (2 :% 4), which isn't reduced, demonstrating that it is
 possible to produce an illegal Rational with the current instance.

 You could also other illegal values such as infinities, NaN-like things,
 negative denominators, etc. before by playing with Data.Data. All of which
 are ruled out by design elsewhere in the API for Rational.

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


More information about the ghc-tickets mailing list