[GHC] #15921: Foldable.maximumBy uses counter-intuitive ordering

GHC ghc-devs at haskell.org
Tue Nov 20 09:05:11 UTC 2018


#15921: Foldable.maximumBy uses counter-intuitive ordering
-------------------------------------+-------------------------------------
           Reporter:  qqwy           |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:  8.6.3
          Component:  Compiler       |           Version:  8.6.2
           Keywords:  List           |  Operating System:  Unknown/Multiple
  maximumBy minimumBy                |
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 {{{#!hs
 Data.List.maximumBy (Data.Ord.comparing snd) [(0, 1), (3, 2), (2, 2), (1,
 1)]
 }}}
 What do you expect the outcome to be?
 All Haskell-programmers I know that I asked this question, would answer,
 based on their intuition,  `(3, 2)`. However, this is not the behaviour
 that `Data.List.maximumBy` currently has: Instead, `(2, 2)` (the ''last''
 occurrence of a 'maximum' element) is kept.

 Furthermore, this behaviour is different from the one used by
 `Data.List.minimumBy`. I would therefore like to request:

 - If its behaviour is unintentionally different from `minimumBy`, alter
 the implementation to match it.
 - If its behaviour is intentionally the opposite, this should be specified
 in the documentation.

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


More information about the ghc-tickets mailing list