Skip to content

Hlint: suggest nub alternative#11825

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

Hlint: suggest nub alternative#11825
philderbeast wants to merge 1 commit 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!

Comment thread Cabal-syntax/src/Distribution/PackageDescription/FieldGrammar.hs
Comment thread Cabal/src/Distribution/Simple/BuildTarget.hs Outdated
@philderbeast philderbeast force-pushed the hlint/suggest-nub-alternatives branch 2 times, most recently from a350dda to d7a010b Compare May 21, 2026 18:13
@philderbeast philderbeast force-pushed the hlint/suggest-nub-alternatives branch from d7a010b to 1d0950b Compare May 22, 2026 14:39
@philderbeast philderbeast added merge me Tell Mergify Bot to merge and removed attention: needs-review labels May 22, 2026
@philderbeast philderbeast force-pushed the hlint/suggest-nub-alternatives branch from 1d0950b to d1dcf19 Compare May 22, 2026 14:42
@mergify mergify Bot added the ready and waiting Mergify is waiting out the cooldown period label May 22, 2026
- Use single letter variables with hlint rules
- Only suggest ordNub
- Add growth rate note
- Include necessary imports
- Follow hlint suggestion: use ordNub
- Follow hlint suggestion: use ordNub in tests
- Satisfy hlint: use fewer imports
- Add @SInCE annotations for added Ord instances
@philderbeast philderbeast force-pushed the hlint/suggest-nub-alternatives branch from d1dcf19 to 64d8543 Compare May 24, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge me Tell Mergify Bot to merge ready and waiting Mergify is waiting out the cooldown period

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an hlint rule not to use nub

3 participants