Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#14249 closed bug (invalid)

ApplicativeDo: Pattern matching on a bind forces a Monad constraint

Reported by: mutantmell Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.2.1
Keywords: ApplicativeDo Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Pattern matching on a bind in 8.2.1 confuses ApplicativeDo, and causes the type to have a Monad constraint where a Functor constraint would suffice.

In GHC 8.0:

> :set -XApplicativeDo
> :t \x -> do { (a, _) <- x; pure (a+1) }
\x -> do { (a, _) <- x; pure (a+1) }
  :: (Num b, Functor f) => f (b, t) -> f b

In GHC 8.2:

> :set -XApplicativeDo
> :t \x -> do { (a, _) <- x; pure (a+1) }
\x -> do { (a, _) <- x; pure (a+1) }
  :: (Num b1, Monad m) => m (b1, b2) -> m b1

Change History (9)

comment:1 Changed 2 years ago by Iceland_jack

Due to #13875?

comment:2 Changed 2 years ago by mutantmell

Adding the ~ to my pattern match changes the constraint, so it looks like it is due to #13875.

I'll close the bug.

comment:3 Changed 2 years ago by mutantmell

Resolution: invalid
Status: newclosed

comment:4 Changed 2 years ago by Iceland_jack

Thanks for filing the ticket, I'm sure you aren't the only one confused by this behavior

comment:5 Changed 2 years ago by mutantmell

I was updating a codebase to 8.2 when I ran into this -- the only thing ghc told me was that my previously valid signature was wrong. Having the compiler output extra information here similar to how it informs the user about Language Extensions would have helped.

comment:6 Changed 2 years ago by bgamari

So you would like something like,

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

Is this right?

comment:7 Changed 2 years ago by mutantmell

That would be excellent, yes.

Do you want me to file a ticket about this, or take some other action?

comment:8 Changed 2 years ago by bgamari

Yes, a ticket would be great. Thanks!

comment:9 Changed 2 years ago by mutantmell

I created #14252, and referenced this ticket and #13875.

Note: See TracTickets for help on using tickets.