如果它有多个Type-parameter,如何使一个类型构造函数成为Functor类型类的一部分?

Chr*_*ris 3 haskell functor type-constructor

我试图了解Functor-Typeclass在Haskell中的工作方式.如果你有一个函数,f :: a -> b -> c并且你想部分地将它argB应用于获取一个带有一个参数的函数,你可以简单地做:

f' :: a -> c
f' x = f x argB
Run Code Online (Sandbox Code Playgroud)

并使用它.当使用类似这样的东西制作Functor-Typeclass的一部分时,是否有可能获得这样的行为:

instance Functor (MyTypeconstructor _ argB) where
   fmap <implementation of fmap>
Run Code Online (Sandbox Code Playgroud)

我知道你可以将Type-constructor部分应用于它的第一个type-parameter(标准currying):

instance Functor (MyTypeconstructor argA) where
   fmap <implementation of fmap>
Run Code Online (Sandbox Code Playgroud)

但是second / third / all except one,如果可能的话,如何将其部分应用于其类型参数?

谢谢.

jak*_*iel 5

假设你有data F a b = ...,定义

newtype Fx a = Fx { unFx :: F a X }
Run Code Online (Sandbox Code Playgroud)

以部分地应用FX在第二个参数.现在你可以使用了

instance Functor Fx where
    fmap f fa = ...
Run Code Online (Sandbox Code Playgroud)

为...定义您的实例F _ X.