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

-XBlockArguments: Avoid Lambda incorrect #1509

Closed
MangoIV opened this issue May 11, 2023 · 9 comments · Fixed by #1634
Closed

-XBlockArguments: Avoid Lambda incorrect #1509

MangoIV opened this issue May 11, 2023 · 9 comments · Fixed by #1634

Comments

@MangoIV
Copy link

MangoIV commented May 11, 2023

  • avoid lambda with BlockArguments doesn't insert parens resulting in an error when applying the hint
  • if BlockArguments are on, it should be checkd if the lambda is in parens and if that's not the case, automatically surround the eta reduced expressions with parens.
@zliu41
Copy link
Collaborator

zliu41 commented Jun 11, 2023

Some examples would be helpful!

@MangoIV
Copy link
Author

MangoIV commented Jun 12, 2023

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
Copy link
Author

MangoIV commented Jun 12, 2023

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

@MangoIV
Copy link
Author

MangoIV commented Jun 12, 2023

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
Copy link
Collaborator

zliu41 commented Jun 12, 2023

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.

@andreasabel
Copy link

Here is an instance I encountered while working in vscode with the hls:

localScope x v = local \ env -> Map.insert x v env

The hint is

Avoid lambda
Found:
\ env -> Map.insert x v env
Why not:
Map.insert x v

If I apply this hint, I am getting the incorrect

localScope x v = local Map.insert x v

A $ is needed after local or (less preferable) parentheses.

@zliu41
Copy link
Collaborator

zliu41 commented Feb 14, 2025

Fix: #1634

@MangoIV
Copy link
Author

MangoIV commented Feb 14, 2025

Thank you for fixing this! ❤️

@zliu41
Copy link
Collaborator

zliu41 commented Feb 14, 2025

@MangoIV Thanks for the bug report. Sorry for the delay, it totally slipped my mind.

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

Successfully merging a pull request may close this issue.

3 participants