Need for extra warning pragma for accidental pattern matching in do blocks
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.
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |