[英]Why does this code that type-checked in GHC 7.10 no longer type check in GHC 8.0.1?
I have the following code: 我有以下代码:
{-# 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)
Using The Glorious Glasgow Haskell Compilation System, version 8.0.1.20161117, this fails to compile: 使用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)
However in GHC 7.10, this compiles without a problem. 但是在GHC 7.10中,编译没有问题。
Is GHC 8 correct, or have I found a bug? GHC 8是正确的,还是我发现了一个错误?
Despite GHC 7.10 accepting it, your code actually makes no sense. 尽管GHC 7.10接受了它,但你的代码实际上没有任何意义。 See https://ghc.haskell.org/trac/ghc/ticket/12784 for discussion. 有关讨论,请参阅https://ghc.haskell.org/trac/ghc/ticket/12784 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.