[GHC] #7913: Argument order not preserved by nubBy
GHC
cvs-ghc at haskell.org
Wed May 15 19:49:28 CEST 2013
#7913: Argument order not preserved by nubBy
-------------------------+--------------------------------------------------
Reporter: paullik | Owner:
Type: bug | Status: new
Priority: normal | Component: Prelude
Version: 7.6.3 | Keywords: nubBy
Os: Linux | Architecture: Unknown/Multiple
Failure: None/Unknown | Blockedby:
Blocking: | Related:
-------------------------+--------------------------------------------------
Hello.
I recently wanted to know how the element 4 in [2,4] is ruled out by:
{{{
nubBy (\x y -> x `mod` y == 0) [2,4]
}}}
and discussing this on #haskell we discovered that the documentation or
the code is buggy.
The [http://hackage.haskell.org/packages/archive/base/latest/doc/html/src
/Data-List.html#nubBy numBy source] states that ''we keep the call to `eq`
with arguments in the same order as in the reference implementation'',
which, comparing the following two lines, is not true:
{{{
nubBy eq (x:xs) = x : nubBy eq (filter (\ y -> not (eq x y)) xs)
elem_by eq y (x:xs) = y `eq` x || elem_by eq y xs
}}}
Also this is easily proved by defining:
{{{
nubBy' eq [] = []
nubBy' eq (x:xs) = x : nubBy' eq (filter (\ y -> not (eq x y)) xs)
}}}
Then running:
{{{
nubBy (\x y -> x `mod` y == 0) [2,4]
}}}
which yields [2] because of '''eq y x''' and
{{{
nubBy' (\x y -> x `mod` y == 0) [2,4]
}}}
which yields [2,4] because of '''eq x y'''.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7913>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list