-
Notifications
You must be signed in to change notification settings - Fork 200
Add "Redundant $ with block argument" hint #1642
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
base: master
Are you sure you want to change the base?
Conversation
Unusually, this hint has two default severities: * Suggestion if BlockArguments is enabled in the module * Ignore otherwise Either way, users can override the severity of this hint as usual.
Thanks for the PR, I like BlockArguments a lot. However, I have two issues with this PR.
For example, save this to {-# LANGUAGE BlockArguments #-}
import Data.Maybe
main =
maybe
(fail "Failed, there are no elements")
(putStrLn . ("Average: " <>) . show) $
-- This block is pure, IO is dispatched above
let
elems = [4.0, 49.0]
in
case elems of
[] -> Nothing
_ -> Just $ sum elems / realToFrac (length elems)
{-# LANGUAGE BlockArguments #-}
import Data.Maybe
main =
maybe
(fail "Failed, there are no elements")
(putStrLn . ("Average: " <>) . show)
-- This block is pure, IO is dispatched above let
elems = [4.0, 49.0]
in
case elems of
[] -> Nothing
_ -> Just $ sum elems / realToFrac (length elems) This is an invalid program, the let became part of the comment. Hlint shouldn't produce invalid programs. (tested with GHC-9.12.2, cabal-install 3.14 and a Cabal index from today) |
HLint should indeed not produce invalid programs, but what you point out is a preexisting bug with HLint refactoring. This program is incorrectly refactored in the same way by HLint 3.6.1: import Data.Maybe
main =
maybe
(fail "Failed, there are no elements")
(putStrLn . ("Average: " <>) . show) $
-- This comment causes the same issue
Nothing I can try to tackle it if that's a blocker for this PR, but maybe it should be its own PR? |
Ok, thanks for investigating, I will make a separate bug report. I am not a maintainer, so I can't say what is a blocker or not. |
After poking around a bit, I suspect the issue would have to be reported and fixed in mpickering/apply-refact. |
Ok, but what about the second bullet point above? If you remove the comment, the let gets indented too far to the right. Is that an issue with this PR or with apply-refact? |
That's purely a formatting issue, and so has to be implemented in apply-refact. But someone would have to spec out the logic of when to join lines together and when to leave them separate, which may not have been necessary before this PR. |
The 'Avoid lambda' suggestion seems to be triggered by the use of BlockArguments. If I remove the extension, and insert the dollar, and run hlint, I don't get the following bad hint. Is this PR aiming to address this issue, or should it be left for an upcoming PR?
Input file: {-# LANGUAGE BlockArguments #-}
import Control.Monad
main =
forM_ [()] \() -> 42 |
That's an issue with #1634. I'd say fix that in a separate PR, since it doesn't interact with this new hint. |
Unusually, this hint has two default severities:
Either way, users can override the severity of this hint as usual.
Fixes #1547.