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