Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

Argument order not preserved by nubBy
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 [numBy source](http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Data-List.html#nubBy) 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**. <details><summary>Trac metadata</summary> | Trac field | Value | | ---------------------- | ------------ | | Version | 7.6.3 | | Type | Bug | | TypeOfFailure | OtherFailure | | Priority | normal | | Resolution | Unresolved | | Component | Prelude | | Test case | | | Differential revisions | | | BlockedBy | | | Related | | | Blocking | | | CC | | | Operating system | | | Architecture | | </details> <!-- {"blocked_by":[],"summary":"Argument order not preserved by nubBy","status":"New","operating_system":"","component":"Prelude","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.6.3","keywords":["nubBy"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Hello.\r\n\r\nI recently wanted to know how the element 4 in [2,4] is ruled out by:\r\n\r\n{{{\r\nnubBy (\\x y -> x `mod` y == 0) [2,4]\r\n}}}\r\n\r\nand discussing this on #haskell we discovered that the documentation or the code is buggy.\r\n\r\nThe [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:\r\n\r\n{{{\r\nnubBy eq (x:xs) = x : nubBy eq (filter (\\ y -> not (eq x y)) xs)\r\n\r\nelem_by eq y (x:xs) = y `eq` x || elem_by eq y xs\r\n}}}\r\n\r\nAlso this is easily proved by defining:\r\n\r\n{{{\r\nnubBy' eq [] = []\r\nnubBy' eq (x:xs) = x : nubBy' eq (filter (\\ y -> not (eq x y)) xs)\r\n}}}\r\n\r\nThen running:\r\n\r\n{{{\r\nnubBy (\\x y -> x `mod` y == 0) [2,4]\r\n}}}\r\n\r\nwhich yields [2] because of '''eq y x''' and \r\n\r\n{{{\r\nnubBy' (\\x y -> x `mod` y == 0) [2,4]\r\n}}}\r\n\r\nwhich yields [2,4] because of '''eq x y'''.","type_of_failure":"OtherFailure","blocking":[]} -->
issue