ndmitchell / hlint

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

`-XBlockArguments`: Avoid Lambda incorrect #1509

Open MangoIV opened 1 year ago

MangoIV commented 1 year ago
zliu41 commented 1 year ago

Some examples would be helpful!

MangoIV commented 1 year ago

Before applying the hint:

{-# LANGUAGE BlockArguments #-}
module BlockArgumentsHlint where

g :: Int -> a -> Bool
g _ _ = True

r :: (Int -> Bool) -> (Int -> Bool)
r = id

f :: Int -> Bool
f = r \x -> g 3 x

after applying the hint:

{-# LANGUAGE BlockArguments #-}
module BlockArgumentsHlint where

g :: Int -> a -> Bool
g _ _ = True

r :: (Int -> Bool) -> (Int -> Bool)
r = id

f :: Int -> Bool
f = r g 3
MangoIV commented 1 year ago

now r takes two arguments when it should actually take only one, what it should do is insert parenthesis around g 3

MangoIV commented 1 year ago

so the correct refactoring would be

{-# LANGUAGE BlockArguments #-}
module BlockArgumentsHlint where

g :: Int -> a -> Bool
g _ _ = True

r :: (Int -> Bool) -> (Int -> Bool)
r = id

f :: Int -> Bool
f = r (g 3)
zliu41 commented 1 year ago

Thanks! This seems more involved than a good first issue, and may or may not have to do with apply-refact. Will have a closer look later.