Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,248
    • Issues 5,248
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 562
    • Merge requests 562
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #7913
Closed
Open
Issue created May 15, 2013 by paullik@trac-paullik

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 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.

Trac metadata
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
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking