5

http://book.realworldhaskell.org/read/monad-transformers.htmlからコピーされたこの MonadState インスタンスでは、GHC 7.4.2 でエラーが発生します。

instance (MonadState s m) => MonadState s (MaybeT m) where
  get = lift get
  put k = lift (put k)

与える

    Illegal instance declaration for `MonadState s (MaybeT m)'
  (All instance types must be of the form (T a1 ... an)
   where a1 ... an are *distinct type variables*,
   and each type variable appears at most once in the instance head.
   Use -XFlexibleInstances if you want to disable this.)
In the instance declaration for `MonadState s (MaybeT m)'

XFlexibleInstances を追加すると、代わりに XUndecidableInstances を追加するように指示されます。ここでこれらの拡張機能は必要ないと思います。このインスタンスをコンパイルするにはどうすればよいですか?

4

1 に答える 1

5

http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/src/Control-Monad-State-Class.html#MonadStateを見ると、"公式」の実装なので、必要だと思います。コメントは、これらのスタックオーバーフローの質問で説明されているカバレッジ条件に関係していると述べています。

この場合、変数 s は右側に存在せず、関数の依存関係は右から左に移動するため、インスタンスは無効です。(UndecidableInstances なし)

于 2013-06-27T18:58:04.620 に答える