3

Learning about functors in Haskell, e.g. [Integer] or [] Integer, I understand that the functor needs to define fmap (in the list example: fmap = map). If I get it right, a functor can implement the sequential application <*> in order to become an applicative functor. This is why

[(1+), (2+)]

is a perfectly fine element of the list instance [] Integer. And an expression like

(+) <$> [1..10] <*> [101..110]

makes sence.

The examples for instances of Functor that I found were all applicative functors, too. I.e. there was a sensible definition of <*>. The typical examples for functors Maybe, [], Either e, Tree, e ->, Pair, (,) e, ... are usually applicative, as well (i.e. there is a sensible definition of <*>). From what I understand they are all monads, even!

I found ZipList as an example of an applicative functor that is not a monad (for a reason).

Now is there a functor that is not an applicative functor and reasonably so?

ruben.moor
  • 1,876
  • 15
  • 27
  • 1
    The `((,) a)` functor, which you can think of as `(a ,)` – Gabriella Gonzalez Oct 08 '14 at 15:03
  • 2
    ....which is only an applicative functor if the (fixed) type a is a monoid. Thus, for example, ((,) Char) is not an applicative functor, even though ((,) String) is. – AndrewC Oct 08 '14 at 15:43
  • Perhaps two composed contravariant functors? This will yield a functor, but I guess an applicative won't be possible. – Edgar Klerks Mar 27 '17 at 15:21
  • @EdgarKlerks This is not so. For example, `data F a = F ( (a -> Int) -> Int)` is a monad - a particular case of the continuation monad - but it is a composition of two contrafunctors. Another, less trivial example is `(a -> Int) -> a`, which is also a monad. Being monads, they are also applicatives. More generally, for any contrafunctor `C`, the functor `(C a) -> a` is a monad and thus also applicative. – winitzki Apr 21 '18 at 02:59

0 Answers0