File tree Expand file tree Collapse file tree 4 files changed +35
-0
lines changed
message-index/messages/GHC-08838 Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ module WrongDoBind where
2
+
3
+ doubleReturn :: forall m . Monad m => m Int
4
+ doubleReturn = return 10
Original file line number Diff line number Diff line change
1
+ module WrongDoBind where
2
+
3
+ doubleReturn :: forall m . Monad m => m Int
4
+ doubleReturn = do
5
+ return (return 10 :: m Int )
6
+ return 10
Original file line number Diff line number Diff line change
1
+
2
+ ---
3
+ title: Double return
4
+ ---
5
+
6
+ In this example, there is a nested return whose result is not bound to a variable. Therefore the computation ` return 10 ` is not used and can be removed.
7
+
8
+ ```
9
+ messages/GHC-08838/WrongDoBind/before/WrongDoBind.hs:5:4: warning: [GHC-08838] [-Wwrong-do-bind]
10
+ A do-notation statement discarded a result of type ‘m Int’
11
+ Suggested fix:
12
+ Suppress this warning by saying ‘_ <- return (return 10 :: m Int)’
13
+ |
14
+ 5 | return (return 10 :: m Int)
15
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
16
+ ```
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Wrong do bind
3
+ summary : Returning a monadic computation in a do block and not binding it will not run it
4
+ severity : warning
5
+ introduced : 9.6.1
6
+ ---
7
+ When using a monadic computation in a do block one should either run it
8
+ directly or bind the result of the computation to a variable. If neither
9
+ is done the monadic computation is never run and can be removed.
You can’t perform that action at this time.
0 commit comments