Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,382
    • Issues 4,382
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 369
    • Merge Requests 369
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #7335

Closed
Open
Opened Oct 16, 2012 by duncan@trac-duncan

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
Assignee
Assign to
8.0.1
Milestone
8.0.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#7335