Skip to content

type-checking regression in 9.6.1-alpha2 - interaction between ApplicativeDo and polymorphic arguments?

Summary

There's a compilation regression between GHC 9.4.3 and GHC 9.6.1-alpha2 which seems to be some interaction between ApplicativeDo and polymorphic arguments.

Cut down example below, which compiles in GHC 9.4.3 but fails in 9.6. It compiles fine in GHC 9.6 if I do any of:

  • remove ApplicativeDo
  • reorder the first two statements in the do
  • remove the pure ()
  • inline go.

It may be related to the ApplicativeDo desugaring itself as I've tried and failed to reproduce the regression with manually desugaring. I also later ran into another example of a regression in an applicative do block, this time with implicit parameters, that was also fixed by reorganising the code; I can also turn that into a test case if wanted.

Now that I understand the triggers I can probably work around it fairly easily in my real code, but I thought it may still be worth investigating as I can't spot any mention in the migration guide or other issues.

Steps to reproduce

{-# LANGUAGE ApplicativeDo #-}
module X where

x :: Maybe ()
x = do
  pure ()
  let go = Nothing
  f go

f :: (forall p . Maybe p) -> Maybe ()
f _ = Nothing

With GHC 9.4.3 this compiles fine.

With GHC 9.6.0-alpha2 I get:

X.hs:8:5: error: [GHC-46956]
    • Couldn't match type ‘a0’ with ‘p’
      Expected: Maybe p
        Actual: Maybe a0
        because type variable ‘p’ would escape its scope
      This (rigid, skolem) type variable is bound by
        a type expected by the context:
          forall p. Maybe p
        at X.hs:8:5-6
    • In the first argument of ‘f’, namely ‘go’
      In a stmt of a 'do' block: f go
      In the expression:
        do pure ()
           let go = Nothing
           f go
    • Relevant bindings include go :: Maybe a0 (bound at X.hs:7:7)
  |
8 |   f go
  |     ^^

Expected behavior

I'm not sure. Maybe it should work in GHC 9.6? Maybe my code is wrong and I just get lucky with earlier GHCs?

Environment

  • GHC version used: 9.6.1-alpha2
Edited by Ganesh Sittampalam
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information