[英]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 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.