#7335: Need for extra warning pragma for accidental pattern matching in do
blocks
------------------------------+---------------------------------------------
Reporter: duncan | Owner:
Type: feature request | Status: new
Priority: normal | Component: Compiler
Version: 7.6.1 | Keywords:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: None/Unknown | Testcase:
Blockedby: | Blocking:
Related: |
------------------------------+---------------------------------------------
There are a few functions (actually monadic actions) where it's almost
always an error to pattern match on the result, e.g.:
{{{
(x,y) <- rpar $ ... -- this is wrong!
(x,y) <- unsafeInterleaveIO $ ... -- this is also wrong!
}}}
We can help users by warning when they do this. To do this sensibly we
would need a new warning pragma.
Here's a suggestion:
{{{
{-# WARN_DO_PATTERNMATCH unsafeInterleaveIO
"You don't want to use pattern matching directly on the
result of unsafeInterleaveIO because that will immediately
force the IO to be done, defeating the intention of lazily
deferring it." #-}
unsafeInterleaveIO :: IO a -> IO a
unsafeInterleaveIO = ...
{-# WARN_DO_PATTERNMATCH rpar "You don't want to use pattern
matching directly on the result of rpar because that will
immediately wait for the result to be evaluated, defeating
the intention of doing it in parallel." #-}
par :: Strategy a
par = ...
}}}
The warning message should probably suggest using a ~ lazy irrefutable
match. Perhaps that bit of the message should be generated rather than
taken from the string in the pragma, since it can provide the actual
pattern the user used, with the extra ~.
As far as I can tell, this is only needed in a 'do' context, not a pure
'case' context.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7335>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs