#4019: deriving Ord can produce incorrect and inefficient instances
---------------------------------+------------------------------------------
    Reporter:  rl                |        Owner:                             
        Type:  bug               |       Status:  new                        
    Priority:  normal            |    Milestone:  6.14.1                     
   Component:  Compiler          |      Version:  6.13                       
    Keywords:                    |   Difficulty:                             
          Os:  Unknown/Multiple  |     Testcase:                             
Architecture:  Unknown/Multiple  |      Failure:  Incorrect result at runtime
       Patch:  0                 |  
---------------------------------+------------------------------------------
Changes (by igloo):

  * milestone:  => 6.14.1


Comment:

 This ticket seems to be mixing several issues. Based on the original
 description, I thought this was the problem you were reporting:

 This derived Ord instance:
 {{{
 data T = T Double deriving( Eq, Ord )
 }}}
 looks like this (after Haskellifying the generated code):
 {{{
 instance Ord T where
     compare a b = cmp_eq a b
         where cmp_eq (T a1) (T b1) = compare a1 b1 }
 }}}
 so it only lifts a minimum number of methods. But it ought to lift all of
 them, rather than relying on the default methods being both correct and
 efficient:
 {{{
 instance Ord T where
     compare a b = cmp_eq a b
         where cmp_eq (T a1) (T b1) = compare a1 b1 }
     (<=) a b = cmp_eq a b
         where cmp_eq (T a1) (T b1) = (<=) a1 b1 }
     (<) a b = cmp_eq a b
         where cmp_eq (T a1) (T b1) = (<) a1 b1 }
     (>=) a b = cmp_eq a b
         where cmp_eq (T a1) (T b1) = (>=) a1 b1 }
     (>) a b = cmp_eq a b
         where cmp_eq (T a1) (T b1) = (>) a1 b1 }
     max a b = cmp_eq a b
         where cmp_eq (T a1) (T b1) = max a1 b1 }
     min a b = cmp_eq a b
         where cmp_eq (T a1) (T b1) = min a1 b1 }
 }}}
 which makes sense to me and I imagine is easy to fix.

 I suggest we leave this ticket to deal with that issue, and open separate
 tickets for other issues.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4019#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to