Opened 2 years ago

Last modified 11 months ago

#14252 new feature request

ApplicativeDo: Add compiler message about irrefutable pattern matches and Monad constraints

Reported by: mutantmell Owned by:
Priority: normal Milestone: 8.10.1
Component: Compiler Version: 8.2.1
Keywords: ApplicativeDo Cc: simonmar, watashi
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by mutantmell)

Add an error message to the compiler when:

  • A user-provided signature specifies a Functor/Applicative constraint
  • ApplicativeDo desugaring requires a Monad constraint
  • Adding a lazy pattern match could allow the Functor/Applicative constraint

bgamari suggests something like the following message:

ApplicativeDo is enabled yet Monad is required due to irrefutable pattern match;
perhaps you want to make the match refutable by adding a ~?


In GHC 8.2.1, ApplicativeDo desugaring was changed to require monad constraints when using a strict pattern match (see #13875 for details). While this behavior is a requirement for maintaining the intended semantics of ApplicativeDo, it is both a breaking change, and somewhat unintuitive (see #14249). Adding a message would provide both clarification around the requirement, and provide a simple resolution for the common use case.

Change History (10)

comment:1 Changed 2 years ago by bgamari

Description: modified (diff)

comment:2 Changed 2 years ago by bgamari

Milestone: 8.4.1

comment:3 Changed 2 years ago by simonpj

When you add warnings like this you end up needing another flag to suppress the warning. What if the user says "No, I didn't to make the match irrefutable; quit bugging me". And then a per-module suppression flag is a bit of a blunt instrument.

I'm not sure what's best; it would be good to get feedback from ApplicativeDo users.

comment:4 Changed 2 years ago by mutantmell

Description: modified (diff)

comment:5 Changed 2 years ago by mutantmell

I changed the wording of the ticket to be more clear with my original intent: add a message when a user provided signature clashes with what ApplicativeDo allows, similar to when enabling an extension would allow code to compile. This should be less obtrusive for users who don't want to be bugged, while providing a message that would help people make their code compile.

comment:6 Changed 22 months ago by bgamari


This ticket won't be resolved in 8.4; remilestoning for 8.6. Do holler if you are affected by this or would otherwise like to work on it.

comment:7 Changed 18 months ago by simonmar

Cc: simonmar added
Keywords: ApplicativeDo added

comment:8 Changed 17 months ago by bgamari


These won't be addressed by GHC 8.6.

comment:9 Changed 12 months ago by watashi

Cc: watashi added

comment:10 Changed 11 months ago by osa1


Bumping milestones of low-priority tickets.

Note: See TracTickets for help on using tickets.