
#15921: Data.List.maximumBy uses counter-intuitive ordering -------------------------------------+------------------------------------- Reporter: qqwy | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.6.2 Resolution: | Keywords: List | maximumBy minimumBy Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by j.waldmann): Documentation already says "the (comparison) function is assumed to define a total ordering". The function `comparing snd` does not. It defines a relation that is total, transitive, reflexive, but not antisymmetric. Then all bets are off, at least officially. There are local `minBy/maxBy` functions in the implementation {{{ min' x y = case cmp x y of GT -> y _ -> x max' x y = case cmp x y of GT -> x _ -> y }}} that treat the `EQ` case differently. That does not feel consistent with the "laws for `Ord` that are expected to hold" (where `EQ` would always select the first argument) {{{ max x y == if x >= y then x else y = True min x y == if x <= y then x else y = True }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15921#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler