A C++ functor is a class that supports overloads the () operator. Is this a functor in the sense of category theory? What are the objects and morphisms?
No, as Hurkyl said, despite of the name clash inferred by "objects" in objects-oriented programming, OOP functors are not related to category theory functors. A better match with OOP would be to rename OOP class
as category
, and conversions between types as functors. Something like this:
category Shape;
category Rectangle : forgetful functor Shape;
category Polygon : forgetful functor Shape
{
functor Polygon( Rectangle & );
};
in place of
class Shape;
class Rectangle : public Shape;
class Polygon : public Shape
{
implicit Polygon( Rectangle & );
};
Alas, the people who developed OOP are not the same as the ones who developed category theory, thus different lingo.
No.
IMO the least confusing way to refer to C++ "functors" is "function object".
In Java I guess an object with a call operator is called a "callable", but in C++ that has a slightly broader meaning, including any function pointer or anything else that can be used with the "call" syntax.
It's just one of these technical terms from math that got appropriated by computer scientists to mean something that basically has nothing to do with its original meaning. Take for instance "network topology", a term that people use to describe the layout of a network. This really has nothing to do with the mathematical meaning of "topology", which is concerned with properties of spaces that are preserved under arbitrary continuous transformations. I.e. "a topologist is a mathematician who cannot tell their coffee cup from their donut". Usually IMO it would make more sense to talk about the "network geometry" of a computer network, for most purposes that people talk about a computer network, since they care about things like distances between nodes, density, bottlenecks, etc. Most of which are not topological properties. But that's just a pet peeve of mine. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With