Why is `((,) r)` a Functor that is NOT an Applicative?

Viewed 818

From functors that are not applicatives:

A type constructor which is a Functor but not an Applicative. A simple example is a pair:

instance Functor ((,) r) where
    fmap f (x,y) = (x, f y)

But there is no way how to define its Applicative instance without imposing additional restrictions on r. In particular, there is no way how to define pure :: a -> (r, a) for an arbitrary r.

Question 1: Why is this so? Here is how pure could work with functions f of type a -> b:

(pure f) (pure x, pure y) = (pure x, pure f y)

From there, the definition of pure :: a -> (r, a) could depend on what r is. For example, if r is Integer, then you could define

pure x = (0 :: Integer, x)

in your instance declaration. So what is the issue?

Question 2: Can we say in general that if F is a functor, then <*> can always be defined, but pure might not always be defined?

2 Answers
Related