Skip to content

Commit e10833e

Browse files
Document GHC-08838 (#543)
* Document GHC-08838 * Update message-index/messages/GHC-08838/index.md --------- Co-authored-by: David Binder <[email protected]>
1 parent af1c27d commit e10833e

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module WrongDoBind where
2+
3+
doubleReturn :: forall m. Monad m => m Int
4+
doubleReturn = return 10
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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.

0 commit comments

Comments
 (0)