Opened 3 years ago

Last modified 3 months ago

#7335 new feature request

Need for extra warning pragma for accidental pattern matching in do blocks

Reported by: duncan Owned by:
Priority: normal Milestone: 8.0.1
Component: Compiler Version: 7.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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.

Change History (5)

comment:1 Changed 3 years ago by igloo

  • difficulty set to Unknown
  • Milestone set to 7.8.1

comment:2 Changed 19 months ago by thoughtpolice

  • Milestone changed from 7.8.3 to 7.10.1

Moving to 7.10.1

comment:3 Changed 12 months ago by thomie

  • Type of failure changed from None/Unknown to Incorrect warning at compile-time

comment:4 Changed 11 months ago by thoughtpolice

  • Milestone changed from 7.10.1 to 7.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:5 Changed 3 months ago by thoughtpolice

  • Milestone changed from 7.12.1 to 8.0.1

Milestone renamed

Note: See TracTickets for help on using tickets.