8
votes

Given the following program:

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

import Control.Monad.Reader

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

The MonadReader deriving declaration should be MonadReader Int. GHC produces the following error message:

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’

This error message is confusing to me. The kind of MonadReader is * -> (* -> *) -> GHC.Prim.Constraint, as the error message states, which makes sense. However, the error message states that it expects kind * -> GHC.Prim.Constraint, despite the fact that MonadReader Int is actually of kind (* -> *) -> GHC.Prim.Constraint.

Given that kinds * and * -> * do not match, this error message feels not only misleading to me, but actually incorrect. Is this a bug, or am I overlooking something in this error message?

1
Looks like a bug with error messages and generalized newtype deriving to me. You could open a ticket on Trac.Tikhon Jelvis
Weird. I'd try standalone deriving to check whether it makes any difference.chi
I've opened a ticket here: ghc.haskell.org/trac/ghc/ticket/12546Alexis King

1 Answers

2
votes

As Tikhon Jelvis said, this was a bug. Alexis King opened this ticket, which was closed as fixed four months ago.