File tree Expand file tree Collapse file tree 7 files changed +74
-0
lines changed
message-index/messages/GHC-81995 Expand file tree Collapse file tree 7 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Unused "do" bind
3
+ summary : A return value of a monadic action is ignored
4
+ severity : warning
5
+ flag : -Wunused-do-bind
6
+ introduced : 9.6.1.
7
+ ---
8
+
9
+ Many monadic actions perform side effects before returning a value.
10
+
11
+ Sometimes, we are only interested in the side effect of a monadic action, and
12
+ not in the return value. In these cases, we should use appropriate functions
13
+ indicating that we purposefully ignore the return value.
14
+
15
+ Even more, in monadic code without side effects such as the list monad, this
16
+ warning may indicate a bug.
Original file line number Diff line number Diff line change
1
+ module List where
2
+
3
+ list :: [Int ]
4
+ -- list = do return 2
5
+ list = [2 ]
Original file line number Diff line number Diff line change
1
+ module List where
2
+
3
+ -- Evaluates to [2].
4
+ list :: [Int ]
5
+ list = do
6
+ return 1 -- This action has no side effects and is completely ignored.
7
+ return 2
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Action without side effect is completely ignored in pure monadic code
3
+ ---
4
+
5
+ # Error message
6
+
7
+ ```
8
+ list/before/List.hs:6:3: warning: [GHC-81995] [-Wunused-do-bind]
9
+ A do-notation statement discarded a result of type ‘Integer’
10
+ Suggested fix: Suppress this warning by saying ‘_ <- return 1’
11
+ |
12
+ 6 | return 1 -- This action has no side effects and is completely ignored.
13
+ | ^^^^^^^^
14
+ ```
Original file line number Diff line number Diff line change
1
+ module GetLine where
2
+
3
+ main :: IO ()
4
+ main = do
5
+ sequence_ [putStrLn " First line" , putStrLn " Second line" ]
6
+ putStrLn " Done."
Original file line number Diff line number Diff line change
1
+ module GetLine where
2
+
3
+ main :: IO ()
4
+ main = do
5
+ sequence [putStrLn " First line" , putStrLn " Second line" ]
6
+ putStrLn " Done."
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Fix warning about unused "do" bind using `sequence_`
3
+ ---
4
+
5
+ For example, ` sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) `
6
+ performs all actions in a traversable container and returns the container with
7
+ the return values. In a similar manner, ` sequence_ ` performs all actions but
8
+ indicates that the we want to ignore the return value.
9
+
10
+ # Error message
11
+ ```
12
+ sequence/before/GetLine.hs:5:3: warning: [GHC-81995] [-Wunused-do-bind]
13
+ A do-notation statement discarded a result of type ‘[()]’
14
+ Suggested fix:
15
+ Suppress this warning by saying
16
+ ‘_ <- sequence [putStrLn "First line", putStrLn "Second line"]’
17
+ |
18
+ 5 | sequence [putStrLn "First line", putStrLn "Second line"]
19
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20
+ ```
You can’t perform that action at this time.
0 commit comments