2016-08-26 52 views
8

考慮下面的程序:爲什麼GHC會產生以下類型的錯誤信息?

{-# LANGUAGE GeneralizedNewtypeDeriving #-} 
{-# LANGUAGE FlexibleInstances #-} 

import Control.Monad.Reader 

newtype AppM a = AppM (ReaderT Int IO a) 
    deriving (Functor, Applicative, Monad, MonadReader) 

MonadReader推導聲明應該是MonadReader Int。 GHC會生成以下錯誤消息:

Expecting one more argument to ‘MonadReader’ 
Expected kind ‘* -> ghc-prim-0.4.0.0:GHC.Prim.Constraint’, 
    but ‘MonadReader’ has kind ‘* 
           -> (* -> *) -> ghc-prim-0.4.0.0:GHC.Prim.Constraint’ 
In the newtype declaration for ‘AppM’ 

此錯誤消息令我困惑。 MonadReader的種類是* -> (* -> *) -> GHC.Prim.Constraint,如錯誤消息所述,這是有道理的。但是,錯誤消息指出它預計種類* -> GHC.Prim.Constraint,儘管事實上MonadReader Int實際上是種類(* -> *) -> GHC.Prim.Constraint

鑑於種類** -> *不匹配,此錯誤消息感覺不僅誤導我,但實際上不正確。這是一個錯誤,還是我忽略了這個錯誤信息中的某些內容?

+6

看起來像一個錯誤消息和廣泛的newtype派生給我的錯誤。您可以在[Trac]上打開一張票(https://ghc.haskell.org/trac/ghc)。 –

+0

奇怪。我會嘗試獨立派生來檢查它是否有任何區別。 – chi

+3

我在這裏打開了一張票:http://ghc.haskell.org/trac/ghc/ticket/12546 –

回答

相關問題