2

以下代码导致错误:

{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, StandaloneDeriving #-}

class Module a b where
    (*>) :: a -> b -> b

data D
newtype DWrapper = DW D    
instance Module D D    
deriving instance Module DWrapper DWrapper

错误:

No instance for (Module DWrapper D) arising from a use of ‘Main.*>’
In the first argument of ‘GHC.Prim.coerce’, namely
  ‘(Main.*>) :: DWrapper -> D -> D’
In the expression:
    GHC.Prim.coerce ((Main.*>) :: DWrapper -> D -> D) ::
      DWrapper -> DWrapper -> DWrapper
In an equation for ‘*>’:
    (*>)
      = GHC.Prim.coerce ((Main.*>) :: DWrapper -> D -> D) ::
          DWrapper -> DWrapper -> DWrapper
When typechecking the code for  ‘Main.*>’
  in a derived instance for ‘Module DWrapper DWrapper’:
  To see the code I am typechecking, use -ddump-deriv

所以 GHC 正在寻找一个Module DWrapper D实例来派生请求的Module D D实例。我猜这是合理的,但不是我想要的。有没有办法告诉 GHC 从哪个实例派生?GNTD 如何在 MPTC 上工作?

4

1 回答 1

5
于 2015-10-21T00:32:31.697 回答