There's a conspiracy to prevent you from understanding functors, and the here are some of the tools used to keep you in the dark:
- In explanations about functional programming, authors blithely use
f
to mean either a function or an object for which there's a functor, e.g.
f :: (a -> b -> c)
fmap :: Functor f => (d -> e) -> f d -> f e
fmap f :: Functor f => f a -> f (b -> c) -- Identify d with a, and e with (b -> c)
- The word functor sometimes means a mapping between categories and other times means an object in a category for which such a mapping exists.
- Back in OO land, people have been using the term functor
since 1992
to mean an object used to encapsulate a function, i.e. pretty much any
class with any method, as long as the intent is to fake a first class function. If the method
is in C++ and called
operator()
or in scala and calledapply()
then it will even look like a function.
That bit about scala's apply()
is a sub-annoyance. The use of the word here has nothing to
do with applicative functors or with the way apply
is used in lisp.
Comments
comments powered by Disqus