Skip to content

Hlint: suggest nub alternative#11825

Open
philderbeast wants to merge 7 commits into
haskell:masterfrom
cabalism:hlint/suggest-nub-alternatives
Open

Hlint: suggest nub alternative#11825
philderbeast wants to merge 7 commits into
haskell:masterfrom
cabalism:hlint/suggest-nub-alternatives

Conversation

@philderbeast
Copy link
Copy Markdown
Collaborator

@philderbeast philderbeast commented May 14, 2026

Fixes #11824.

When fired, this suggestion renders as:

$ cabal-install-solver/src/Distribution/Solver/Modular/Assignment.hs:56:64-69: Suggestion: Use ordNub
Found:
  nub xs
Perhaps:
  ordNub xs
Note: The growth rate of nub is O(n^2) and for ordNub it is O(n log n).  May require adding import of either;
  - Distribution.Utils.Generic from Cabal-syntax, or
  - Distribution.Simple.Utils from Cabal.

I didn't correct O(n log n) to the O(n log d) from containers haddocks for nubOrd. Neither did I suggest using that equivalent function from containers. For that, I raised #11826.

I had to add Ord instances to a few data types, BuildTarget and MatchError. I changed the Eq constraint to an Ord constraint for findMatch and nubMatches.

I left a note in .hlint.yaml to only use single letter variables in rules.

I used a separate commit for changes to tests but on approval will squash all commits before adding the merge me label.


  • Patches conform to the coding conventions.
  • Is this a PR that fixes CI? If so, it will need to be backported to older cabal release branches (ask maintainers for directions).

Copy link
Copy Markdown
Collaborator

@jappeace jappeace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

| n <-
nub $
ordNub $
sort $
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the sort no longer needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an hlint rule not to use nub

2 participants