1
{-# LANGUAGE Haskell2010 #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}

class PoC m where
    type Wrapper m :: * -> *
    wrap :: l -> Wrapper m l

私は haskell-src-exts を使用しています。AST をアップグレードして、新たに生成可能なラベルを作成したいと考えています。拡張可能な方法で実行したいので、上記のコードのようなインターフェイスを作成しました。ただし、AST をアップグレードするコードは機能しません。私は次のものを持っています:

upgrade :: forall f m l. (PoC m, Functor f) => f l -> f (Wrapper m l)
upgrade x = fmap (wrap :: l -> Wrapper m l) x

しかし、を使用しても使用しなくてもScopedTypeVariables、同じエラーが発生します。

/tmp/PoC.hs:10:19:
    Could not deduce (Wrapper m ~ Wrapper m0)
    from the context (PoC m, Functor f)
      bound by the type signature for
                 upgrade :: (PoC m, Functor f) => f l -> f (Wrapper m l)
      at /tmp/PoC.hs:9:12-69
    NB: `Wrapper' is a type function, and may not be injective
    The type variable `m0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Expected type: l -> Wrapper m0 l
      Actual type: l -> Wrapper m l
    In the first argument of `fmap', namely
      `(wrap :: l -> Wrapper m l)'
    In the expression: fmap (wrap :: l -> Wrapper m l) x
    In an equation for `upgrade':
        upgrade x = fmap (wrap :: l -> Wrapper m l) x

しかし、GHC がこれをバインドする場所がわかりませんm0。ここでの問題の核心は「単射ではないかもしれない」ですか?

4

1 に答える 1