-
Notifications
You must be signed in to change notification settings - Fork 70
GHC-81995: add error message and example using sequence
#526
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: Unused "do" bind | ||
summary: A return value of a monadic action is ignored | ||
severity: warning | ||
flag: -Wunused-do-bind | ||
introduced: 9.6.1. | ||
--- | ||
|
||
Many monadic actions perform side effects before returning a value. | ||
|
||
Sometimes, we are only interested in the side effect of a monadic action, and | ||
not in the return value. In these cases, we should use appropriate functions | ||
indicating that we purposefully ignore the return value. | ||
|
||
Even more, in monadic code without side effects such as the list monad, this | ||
warning may indicate a bug. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module List where | ||
|
||
list :: [Int] | ||
-- list = do return 2 | ||
list = [2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module List where | ||
|
||
-- Evaluates to [2]. | ||
list :: [Int] | ||
list = do | ||
return 1 -- This action has no side effects and is completely ignored. | ||
return 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
title: Action without side effect is completely ignored in pure monadic code | ||
--- | ||
|
||
# Error message | ||
|
||
``` | ||
list/before/List.hs:6:3: warning: [GHC-81995] [-Wunused-do-bind] | ||
A do-notation statement discarded a result of type ‘Integer’ | ||
Suggested fix: Suppress this warning by saying ‘_ <- return 1’ | ||
| | ||
6 | return 1 -- This action has no side effects and is completely ignored. | ||
| ^^^^^^^^ | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module GetLine where | ||
|
||
main :: IO () | ||
main = do | ||
sequence_ [putStrLn "First line", putStrLn "Second line"] | ||
putStrLn "Done." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module GetLine where | ||
|
||
main :: IO () | ||
main = do | ||
sequence [putStrLn "First line", putStrLn "Second line"] | ||
putStrLn "Done." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: Fix warning about unused "do" bind using `sequence_` | ||
--- | ||
|
||
For example, `sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)` | ||
performs all actions in a traversable container and returns the container with | ||
the return values. In a similar manner, `sequence_` performs all actions but | ||
indicates that the we want to ignore the return value. | ||
|
||
# Error message | ||
``` | ||
sequence/before/GetLine.hs:5:3: warning: [GHC-81995] [-Wunused-do-bind] | ||
A do-notation statement discarded a result of type ‘[()]’ | ||
Suggested fix: | ||
Suppress this warning by saying | ||
‘_ <- sequence [putStrLn "First line", putStrLn "Second line"]’ | ||
| | ||
5 | sequence [putStrLn "First line", putStrLn "Second line"] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.