为什么这段在 GHC 7.10 中进行了类型检查的代码在 GHC 8.0.1 中不再进行类型检查?

Why does this code that type-checked in GHC 7.10 no longer type check in GHC 8.0.1?

我有以下代码:

{-# LANGUAGE DefaultSignatures#-}

import Control.Monad.Trans.Class
import Control.Monad.Trans.Maybe

class Monad m => MonadMaybe m where
  liftMaybe :: Maybe a -> m a
  default liftMaybe :: (MonadTrans t, MonadMaybe m) => Maybe a -> t m a
  liftMaybe = lift . liftMaybe

instance MonadMaybe m => MonadMaybe (MaybeT m)

使用Glorious Glasgow Haskell编译系统,版本8.0.1.20161117,编译失败:

foo.hs:11:10: error:
    • Couldn't match type ‘m’ with ‘MaybeT m’
      ‘m’ is a rigid type variable bound by
        the instance declaration at foo.hs:11:10
      Expected type: Maybe a -> MaybeT m a
        Actual type: Maybe a -> MaybeT (MaybeT m) a
    • In the expression: Main.$dmliftMaybe @MaybeT m
      In an equation for ‘liftMaybe’:
          liftMaybe = Main.$dmliftMaybe @MaybeT m
      In the instance declaration for ‘MonadMaybe (MaybeT m)’
    • Relevant bindings include
        liftMaybe :: Maybe a -> MaybeT m a (bound at foo.hs:11:10)

但是在 GHC 7.10 中,编译没有问题。

GHC 8 是否正确,还是我发现了错误?

尽管 GHC 7.10 接受它,但您的代码实际上没有任何意义。请参阅 https://ghc.haskell.org/trac/ghc/ticket/12784 进行讨论。