Partially applying type in type constructor

In the book "Teach you Haskell", chapter 11, we introduce the keyword newtype, and all this makes sense to me to the point where we see that the type of the pair is created as an instance of Functor.

This discussion begins with a statement about the problem that "only type constructors that take exactly one parameter can be made an instance of Functor." I do not understand this statement. Where is this restriction ever described?

In the context of the discussion, we have a pair of type defined as:

newtype Pair b a = Pair { getPair :: (a,b) }

Given this, I would think that we could use something like:

instance Functor (Pair a b) where ...

I would think that (pair ab) will replace the “f” in the Functor definition without any problems. What keeps it from working?

Further, the author continues to make Pair an instance of Functor using the following:

instance Functor (Pair c) where ...

. , - " " . , , , , .

, -, , . , , .

+4
1

" , , Functor." . - ?

fmap Functor:

class Functor f where
    fmap :: (a -> b) -> f a -> f b

f f a, , Functor, . f a , f . ( , f , , , , .)

, , - :

instance Functor (Pair a b) where ...

, ( a b) "f" Functor - . ?

fmap, . Pair c d f ( a c b d, ),

fmap :: (a -> b) -> Pair c d a -> Pair c d b

.

. , - " " .

... . =)

, , , , .

, : Pair a , . , , Pair a, Int, Pair a Int. , , , ; fmap Pair c

fmap :: (a -> b) -> Pair c a -> Pair c b

, Pair c a Pair c b , Pair c d a Pair c d b , , .

+7

Source: https://habr.com/ru/post/1670671/


All Articles