ndmitchell/hlint

Incorrect "Use map" when folding over a `Foldable`

开放

#1,601 创建于 2024年5月29日

 (1 条评论) (0 个反应) (0 位负责人)Haskell (208 个派生)batch import
good first issue

仓库指标

星标
 (1,602 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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)

贡献者指南