I am trying to understand the way the Functor-Typeclass works in Haskell. If you have a function f :: a -> b -> c
and you want to partially apply it to the argB
to get a function that takes one argument, you can simply do:
f' :: a -> c
f' x = f x argB
and use that. Is it possible to get such behavior when making something part of the Functor-Typeclass with something like this:
instance Functor (MyTypeconstructor _ argB) where
fmap <implementation of fmap>
I know you can partially apply a Type-constructor to its first type-parameter (standart currying):
instance Functor (MyTypeconstructor argA) where
fmap <implementation of fmap>
but how can you partially apply it to its second / third / all except one
type-parameter, if this is possible?
thank you.
Suppose you have data F a b = ...
, define
newtype Fx a = Fx { unFx :: F a X }
to partially apply F
to X
in the second argument. Now you can use
instance Functor Fx where
fmap f fa = ...
to define your instance for F _ X
.