Do notation in pattern match [GHC-06446]

When pattern matching, do expressions are not allowed as patterns to be matched against.

Instead, either match on a variable within the do block, or on the value the do block itself evaluates to.

Examples

Do notation in pattern match

When pattern matching, do expressions are not allowed as patterns to be matched against.

Error Message

DoNotationInPattern.hs:4:4: error: [GHC-06446]
    do-notation in pattern
  |
4 | f (do a; b; c;) = do
  |    ^^^^^^^^^^
DoNotationInPattern.hs
Before
module DoNotationInPattern where

f :: Monad m => m Int -> m Bool
f (do a; b; c) = do
    v <- c
    return $ v == 2
After
module DoNotationInPattern where

f :: Monad m => m Int -> m Bool
f m = do
    v <- m
    return $ v == 2