Skip to content

Type inference regression with RankNTypes (GHC 8.1)

The following module compiles fine with ghc-8.0.1:

{-# LANGUAGE RankNTypes #-}

module Acquire where

newtype Acquire a = Acquire {unAcquire :: (forall b. b -> b) -> IO a}

instance Functor Acquire where
    fmap = undefined

instance Applicative Acquire where
    pure = undefined
    (<*>) = undefined

instance Monad Acquire where
    Acquire f >>= g' = Acquire $ \restore -> do
        x <- f restore
        let Acquire g = g' x
        -- let g = unAcquire (g' x)
        g restore

HEAD (83e4f495, ghc-8.1.20160720) reports:

Acquire.hs:17:21: error:
    • Couldn't match expected type ‘t’
                  with actual type ‘(forall b1. b1 -> b1) -> IO b’
      ‘t’ is a rigid type variable bound by
        the inferred type of g :: t at Acquire.hs:17:13-28
    • In the pattern: Acquire g
      In a pattern binding: Acquire g = g' x
      In the expression:
        do { x <- f restore;
             let Acquire g = g' x;
             g restore }
    • Relevant bindings include
        g' :: a -> Acquire b (bound at Acquire.hs:15:19)
        (>>=) :: Acquire a -> (a -> Acquire b) -> Acquire b
          (bound at Acquire.hs:15:15)

This example is reduced from the recourcet package on Hackage, module Data.Acquire.Internal.

Trac metadata
Trac field Value
Version 8.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information