Wrong do bind [GHC-08838]

When using a monadic computation in a do block one should either run it directly or bind the result of the computation to a variable. If neither is done the monadic computation is never run and can be removed.

Examples

index

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.

messages/GHC-08838/WrongDoBind/before/WrongDoBind.hs:5:4: warning: [GHC-08838] [-Wwrong-do-bind]
    A do-notation statement discarded a result of type ‘m Int’
    Suggested fix:
      Suppress this warning by saying ‘_ <- return (return 10 :: m Int)’
  |
5 |    return (return 10 :: m Int)
  |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
WrongDoBind.hs
Before
module WrongDoBind where

doubleReturn :: forall m. Monad m => m Int
doubleReturn = do
  return (return 10 :: m Int)
  return 10
After
module WrongDoBind where

doubleReturn :: forall m. Monad m => m Int
doubleReturn = return 10