[GHC] #15696: Derived Ord instance for enumerations with more than 8 elements seems to be incorrect

GHC ghc-devs at haskell.org
Tue Oct 2 16:14:56 UTC 2018


#15696: Derived Ord instance for enumerations with more than 8 elements seems to be
incorrect
-------------------------------------+-------------------------------------
        Reporter:  mrkkrp            |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  highest           |            Milestone:  8.6.2
       Component:  Compiler          |              Version:  8.6.1
      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 simonpj):

 Avoiding the use of type classes:
 {{{
 main :: IO ()
 main = print $ cmpT a T2
   where
     {-# NOINLINE f #-}
     f = T2
     {-# NOINLINE a #-}
     a = f

 data T = T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9
 --  deriving (Eq, Show, Ord)

 cmpT a b
     = case dataToTag# a of
         a' -> case dataToTag# b of
                 b' -> if tagToEnum# (a' <# b') :: Bool then
                           LT
                       else
                           if tagToEnum# (a' ==# b') :: Bool then
                               EQ
                           else
                               GT
 }}}
 With `-O` we get `LT` for GHC 8.4 and 8.2 and earlier versions.  Without
 `-O` it returns `EQ` as it should.

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


More information about the ghc-tickets mailing list