Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect "Use map" when folding over a Foldable #1601

Open
slotThe opened this issue May 29, 2024 · 0 comments
Open

Incorrect "Use map" when folding over a Foldable #1601

slotThe opened this issue May 29, 2024 · 0 comments

Comments

@slotThe
Copy link

slotThe commented May 29, 2024

The code

triggersUseMap :: Foldable f => f a -> [a]
triggersUseMap = foldr (\k acc -> identity k : acc) []

-- to get rid of "Avoid lambda" and "Redundant id"
identity :: a -> a
identity = id

triggers the hint

                        Warning: Use map
Found:
  foldr (\ k acc -> identity k : acc) []
Perhaps:
  map (\ k -> identity k)

but obviously triggersUseMap = map (\k -> identity k) does not compile, since map wants a list and the argument is a general Foldable.

The same warning is not emitted with the eta reduced version:

noHint :: Foldable f => f a -> [a]
noHint = foldr ((:) . identity) [] -- no hint even with foldr (:) []

This is using GHC 9.6.5 with HLint 3.6.1 (apologies if this was already fixed in 3.8, but I didn't see anything of the sort in the changelog)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant