为什么GHC会产生以下类型的错误消息?

时间:2016-08-26 18:25:11

标签: haskell 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种类。

鉴于种类** -> *不匹配,此错误消息不仅会误导我,而且实际上不正确。这是一个错误,还是我忽略了此错误消息中的内容?

1 个答案:

答案 0 :(得分:2)

作为Tikhon Jelvis said,这是一个错误。亚历克西斯·金开了this ticket,四个月前关闭了。