ndmitchell / hlint

Haskell source code suggestions
Other
1.48k stars 195 forks source link

traverse/mapM for sequence and `<$>` #1508

Closed Lev135 closed 1 year ago

Lev135 commented 1 year ago

Hlint suggests to replace sequence . fmap f and sequence (fmap f a) with mapM, but it doesn't for sequence (f <$> a). Is there any reason not to do so or this case is just accidently missed?

batkot commented 1 year ago

Hi @Lev135

I tried to recreate it, but it seems to work fine with current master (5d33243) :thinking:

Sample file:

module MapM (foo, foo2, foo3) where

foo f x = sequence (fmap f x)

foo2 f = sequence . fmap f

foo3 f x = sequence (f <$> x)
$ stack exec -- hlint MapM.hs

MapM.hs:3:11-29: Warning: Use mapM
Found:
  sequence (fmap f x)
Perhaps:
  mapM f x

MapM.hs:5:10-26: Warning: Use mapM
Found:
  sequence . fmap f
Perhaps:
  mapM f

MapM.hs:7:12-29: Warning: Use mapM
Found:
  sequence (f <$> x)
Perhaps:
  mapM f x

3 hints
zliu41 commented 1 year ago

HLint 3.4.1 indeed suggests mapM for sequence (f <$> a). Closing the issue.

Lev135 commented 1 year ago

Sorry for disturbing you. I really have an old version.