ndmitchell / hlint

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

Add hints for when 'x <*> y' could be 'y' #1617

Closed ysangkok closed 1 month ago

ysangkok commented 1 month ago

I haven't added all the alternatives with mempty and empty as hlint doesn't know about types, and there could be lawless instances out there I suppose. So it's safer just to deal with concrete types.

ghci> :{
ghci| let f :: Applicative m => m (b -> (Int, b))
ghci|     f = (,) <$> pure 5
ghci| :}
ghci> f <*> mempty :: Ap [] (Int, Sum Int)
Ap {getAp = [(5,Sum {getSum = 0})]}
ghci> f <*> empty :: Ap [] (Int, Sum Int)
Ap {getAp = []}

Would be nice to detect the last one, but hlint can't know that it's empty on Ap [] (..., Sum ...).

ndmitchell commented 1 month ago

Thanks!