diff --git a/message-index/messages/GHC-81995/index.md b/message-index/messages/GHC-81995/index.md new file mode 100644 index 00000000..39db8776 --- /dev/null +++ b/message-index/messages/GHC-81995/index.md @@ -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. diff --git a/message-index/messages/GHC-81995/list/after/List.hs b/message-index/messages/GHC-81995/list/after/List.hs new file mode 100644 index 00000000..0fc0c286 --- /dev/null +++ b/message-index/messages/GHC-81995/list/after/List.hs @@ -0,0 +1,5 @@ +module List where + +list :: [Int] +-- list = do return 2 +list = [2] diff --git a/message-index/messages/GHC-81995/list/before/List.hs b/message-index/messages/GHC-81995/list/before/List.hs new file mode 100644 index 00000000..d028dde8 --- /dev/null +++ b/message-index/messages/GHC-81995/list/before/List.hs @@ -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 diff --git a/message-index/messages/GHC-81995/list/index.md b/message-index/messages/GHC-81995/list/index.md new file mode 100644 index 00000000..d4b34772 --- /dev/null +++ b/message-index/messages/GHC-81995/list/index.md @@ -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. + | ^^^^^^^^ +``` diff --git a/message-index/messages/GHC-81995/sequence/after/GetLine.hs b/message-index/messages/GHC-81995/sequence/after/GetLine.hs new file mode 100644 index 00000000..750b47d6 --- /dev/null +++ b/message-index/messages/GHC-81995/sequence/after/GetLine.hs @@ -0,0 +1,6 @@ +module GetLine where + +main :: IO () +main = do + sequence_ [putStrLn "First line", putStrLn "Second line"] + putStrLn "Done." diff --git a/message-index/messages/GHC-81995/sequence/before/GetLine.hs b/message-index/messages/GHC-81995/sequence/before/GetLine.hs new file mode 100644 index 00000000..b6848c03 --- /dev/null +++ b/message-index/messages/GHC-81995/sequence/before/GetLine.hs @@ -0,0 +1,6 @@ +module GetLine where + +main :: IO () +main = do + sequence [putStrLn "First line", putStrLn "Second line"] + putStrLn "Done." diff --git a/message-index/messages/GHC-81995/sequence/index.md b/message-index/messages/GHC-81995/sequence/index.md new file mode 100644 index 00000000..60ebd562 --- /dev/null +++ b/message-index/messages/GHC-81995/sequence/index.md @@ -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"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +```