鉴于以下计划:
{-# 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
种类。
鉴于种类*
和* -> *
不匹配,此错误消息不仅会误导我,而且实际上不正确。这是一个错误,还是我忽略了此错误消息中的内容?