Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Unification errors on GHC 7.7 #54

Closed
bgamari opened this Issue · 5 comments

4 participants

@bgamari

I've only tested on ARM so far but I don't see any reason why this shouldn't be reproducible elsewhere.

[28 of 96] Compiling Control.Monad.AnyCont.Class ( src/Control/Monad/AnyCont/Class.hs, dist/build/Control/Monad/AnyCont/Class.o )

src/Control/Monad/AnyCont/Class.hs:29:16:
    Cannot instantiate unification variable ‛a1’
    with a type involving foralls: forall r. (a -> b r) -> b r
      Perhaps you want -XImpredicativeTypes
    In the expression: lift . anyContToM
    In an equation for ‛anyContToM’: anyContToM = lift . anyContToM
    In the instance declaration for ‛MonadAnyCont b (StateT s m)’

src/Control/Monad/AnyCont/Class.hs:29:23:
    Cannot instantiate unification variable ‛a1’
    with a type involving foralls: forall r. (a -> b1 r) -> b1 r
      Perhaps you want -XImpredicativeTypes
    In the second argument of ‛(.)’, namely ‛anyContToM’
    In the expression: lift . anyContToM

src/Control/Monad/AnyCont/Class.hs:36:16:
    Cannot instantiate unification variable ‛a0’
    with a type involving foralls: forall r. (a -> b r) -> b r
      Perhaps you want -XImpredicativeTypes
    In the expression: lift . anyContToM
    In an equation for ‛anyContToM’: anyContToM = lift . anyContToM
    In the instance declaration for ‛MonadAnyCont b (ErrorT e m)’

src/Control/Monad/AnyCont/Class.hs:36:23:
    Cannot instantiate unification variable ‛a0’
    with a type involving foralls: forall r. (a -> b0 r) -> b0 r
      Perhaps you want -XImpredicativeTypes
    In the second argument of ‛(.)’, namely ‛anyContToM’
    In the expression: lift . anyContToM
Failed to install llvm-general-3.4.0.0
@cartazio

Looking at the module in question, looks pretty innocuous... but I could be wrong. Or is this a bug in ghc head?

{-# LANGUAGE
  RankNTypes,
  MultiParamTypeClasses,
  UndecidableInstances
  #-}
module Control.Monad.AnyCont.Class where

import Control.Monad.Trans.Class
import Control.Monad.Trans.AnyCont (AnyContT)
import qualified Control.Monad.Trans.AnyCont as AnyCont
import Control.Monad.Trans.Error as Error
import Control.Monad.Trans.State as State

class ScopeAnyCont m where
  scopeAnyCont :: m a -> m a

class MonadAnyCont b m where
  anyContToM :: (forall r . (a -> b r) -> b r) -> m a


instance MonadTransAnyCont b m => MonadAnyCont b (AnyContT m) where
  anyContToM c = AnyCont.anyContT (liftAnyCont c)

instance Monad m => ScopeAnyCont (AnyContT m) where
  scopeAnyCont = lift . flip AnyCont.runAnyContT return


instance (Monad m, MonadAnyCont b m) => MonadAnyCont b (StateT s m) where
  anyContToM = lift . anyContToM

instance ScopeAnyCont m => ScopeAnyCont (StateT s m) where
  scopeAnyCont = StateT . (scopeAnyCont .) . runStateT


instance (Error e, Monad m, MonadAnyCont b m) => MonadAnyCont b (ErrorT e m) where
  anyContToM = lift . anyContToM

instance ScopeAnyCont m => ScopeAnyCont (ErrorT e m) where
  scopeAnyCont = mapErrorT scopeAnyCont




class MonadTransAnyCont b m where
  liftAnyCont :: (forall r . (a -> b r) -> b r) -> (forall r . (a -> m r) -> m r)

instance MonadTransAnyCont b b where
  liftAnyCont c = c

instance MonadTransAnyCont b m => MonadTransAnyCont b (StateT s m) where
  liftAnyCont c = (\c q -> StateT $ \s -> c $ ($ s) . runStateT . q) (liftAnyCont c)

instance MonadTransAnyCont b m => MonadTransAnyCont b (ErrorT e m) where
  liftAnyCont c = (\c q -> ErrorT . c $ runErrorT . q) (liftAnyCont c)
@cartazio

for completeness heres the AnyCont module

{-# LANGUAGE
  RankNTypes
  #-}
module Control.Monad.Trans.AnyCont where

import Control.Applicative
import Control.Monad.Cont

newtype AnyContT m a = AnyContT { unAnyContT :: forall r . ContT r m a }

instance Functor (AnyContT m) where
  fmap f p = AnyContT $ fmap f . unAnyContT $ p

instance Applicative (AnyContT m) where
  pure a = AnyContT $ pure a
  f <*> v = AnyContT $ unAnyContT f <*> unAnyContT v

instance Monad m => Monad (AnyContT m) where
  AnyContT f >>= k = AnyContT $ f >>= unAnyContT . k
  return a = AnyContT $ return a
  fail s = AnyContT (ContT (\_ -> fail s))

instance MonadIO m => MonadIO (AnyContT m) where
  liftIO = lift . liftIO

instance MonadTrans AnyContT where
  lift ma = AnyContT (lift ma)

runAnyContT :: AnyContT m a -> (forall r . (a -> m r) -> m r)
runAnyContT = runContT . unAnyContT
anyContT :: (forall r . (a -> m r) -> m r) -> AnyContT m a
anyContT f = AnyContT (ContT f)

withAnyContT :: (forall r . (b -> m r) -> (a -> m r)) -> AnyContT m a -> AnyContT m b
withAnyContT f m = anyContT $ runAnyContT m . f

mapAnyContT :: (forall r . m r -> m r) -> AnyContT m a -> AnyContT m a
mapAnyContT f m = anyContT $ f . runAnyContT m
@thoughtpolice

As I wrote here, this is the expected behavior in GHC HEAD. The fix is to change the instances on line 29 & 36 from:

anyContToM = lift . anyContToM

to:

anyContToM x = lift $ anyContToM x
@bscarlet
Owner

I've merged the associated PR, but will leave this issue open to remind me to merge it across branches & push out a new release on hackage.

@bscarlet
Owner

Now merged & pushed out to hackage.

@bscarlet bscarlet closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.