polysemy-research / polysemy-zoo

:monkey::panda_face: Experimental, user-contributed effects and interpreters for polysemy
BSD 3-Clause "New" or "Revised" License
70 stars 21 forks source link

ghc 9 - Couldn't match MonadCatch with MonadThrow #69

Closed funketh closed 3 years ago

funketh commented 3 years ago

MonadCatch hasn't been touched since 2019 so this probably has something to do with ghc 9 changes.

[ 3 of 31] Compiling Polysemy.ConstraintAbsorber.MonadCatch

/home/theo/prj/polysemy-zoo/src/Polysemy/ConstraintAbsorber/MonadCatch.hs:83:20: error:
    * Couldn't match type: C.MonadCatch (Sem r)
                     with: C.MonadThrow (Sem r)
      Expected: (C.MonadThrow (Sem r) => Sem r a) -> Sem r a
        Actual: (C.MonadCatch (Sem r) => Sem r a) -> Sem r a
    * In the expression: absorbMonadCatch
      In an equation for `absorbMonadThrow':
          absorbMonadThrow = absorbMonadCatch
    * Relevant bindings include
        absorbMonadThrow :: (C.MonadThrow (Sem r) => Sem r a) -> Sem r a
          (bound at src/Polysemy/ConstraintAbsorber/MonadCatch.hs:83:1)
   |                        
83 | absorbMonadThrow = absorbMonadCatch
   |                    ^^^^^^^^^^^^^^^^

The stack.yaml I used:

compiler: ghc-9.0.1
resolver: nightly-2020-05-07

allow-newer: true

packages:
- .

extra-deps:
- atomic-primops-0.8.4
- compact-0.2.0.0
- random-1.2.0
- splitmix-0.1.0.3
- syb-0.7.2.1
- th-abstraction-0.4.2.0
- QuickCheck-2.14.2
# GHC 9 patch (not yet on hackage)
- github: polysemy-research/polysemy
  commit: 09c65bdae9c9ce50a55c7ee2ab9681916f09f4c3
  subdirs: [.]
KingoftheHomeless commented 3 years ago

I think this is because of the loss of function contravariance. Haskell can't tell that (MonadThrow (Sem r) => Sem r a) -> Sem r a can be subsumed by (MonadCatch (Sem r) => Sem r a) -> Sem r a, so it certainly looks like it. I never thought the change would have this kind of impact.

Does simple eta-expansion resolve the issue? I'm somewhat scared that it won't.

absorbMonadThrow main = absorbMonadCatch main