Everything2
Near Matches
Ignore Exact
Full Text
Everything2

functor

created by ariels

(thing) by ariels (1.9 d) (print)   ?   1 C! I like it! Fri Sep 01 2000 at 20:18:27

In category theory, a functor is what takes you from one category to another. If X and Y are categories, a functor F from X to Y takes each node A of X to a node FA of Y, in such a way that if A -> B then FA -> FB. That is, it preserves arrows!

Examples:

  • If X is almost any category, it has a "forgetful functor" which copies every node A to the set A of its elements. For example, this lets you treat groups as just the sets of their elements, forgetting the special group structure defined on them. This functor is the basis of rp's assertion in his writeup under category theory that "nodes are sets". They're not, but we can usually think of them as sets by forgetting about their extra properties.
  • If A is a category and A' a pointed category based on A, there is a slightly less forgetful functor from A' to A which takes (A,a) to A (it "forgets" about a).
  • The category Group of groups has a nice functor from Group to Group which takes every group G to a group with exactly the same elements, but the operation takes the elements in opposite order. The groups which this functor takes to themselves are exactly the category of Abelian groups.
If you've just read category theory, you might recognise all of this as being very familiar. And it is! If you look at the Class of all categories (this is a really Big Object, which doesn't even exist in something as puny as Zermelo Fraenkel set theory!), you can create the Category of all categories as follows: every category is a node, and the functors between categories are arrows! This lets you warp your mind with abstract nonsense. Beginners at category theory really like this, as it shows how fundamental category theory is: it even covers itself! It also makes set theorists nervous, as this is exactly the territory the Barber paradox treads on...

(thing) by munificent (6.6 y) (print)   ?   I like it! Thu Feb 22 2001 at 8:14:59

In C++ a functor is the name of a special kind of operator overloading. Defining a functor for a class allows you to treat an object as if it were a function. This can be confusing, so is rarely seen. An example would be:

class CSquare
{
public:
    CSquare(){}
    int operator()( int i )
    { return( i * i ); }
};

Then, using the above class definition, you could write something like the following:

int main()
{
    CSquare square;

    int s = square( 5 );
}

One possible use for functors is for multiple subscript arrays (i.e. matrices). Since overloading the bracket operator only allows a single parameter inside the brackets, you could instead define a functor that taks multiple subscripts.


(thing) by brainer (2.5 y) (print)   ?   I like it! Wed Aug 22 2001 at 14:47:57

Although functors have been identified with function objects in print (Coplien?), calling "operator()", or an object that defines it, a "functor" is not universally agreed-upon usage with C++. As far as I know, the term functor has been used in mathematics for probably a century or longer for a mapping that maps functions to other things, for example to numbers. In programming terms, a functor would be a function whose argument type is a function type.

Example:
typedef void (function_t)(); // Type of a function taking no args and
                             // returning void

int functor(function_t * const arg); // direct declaration of a function
                                     // that is a functor

Sure, functor may sound cooler than function object or operator(), but using it with this meaning unnecessarily ambiguates it.

(Does this make me a pedant? ;-)

(person) by RoseAndSigil (2.4 mon) (print)   ?   I like it! Thu May 15 2003 at 21:36:46

"Functor" is also the nickname of the Carnegie Mellon University's School of Computer Science's mascot. Functor is a dragon, and is named in honor of Trogdor the Burninator.

printable version
chaos

abstract nonsense category theory Barber Paradox Trogdor
C++: objects with no type Fundamental theorem of finite abelian groups class dual of a vector space
C++ Operator overloading natural transformation C++: brackets to make an object not a function
Cartesian Closed Category ML C++ function binders node
First-class Carnegie Mellon University Matrix set theory
functional Arrow Signs and symptoms of psychiatric disorders RP
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Drink up!
My biological clock is not ticking, dammit!
Dem Bones
Carousel of Progress
Robert Falcon Scott
Using Pavlovian Theory to classically condition inanimate objects
Saving Private Ryan
Zardoz
The Vagina Monologues
night vision
English Civil War
octocontrabass clarinet
Causa Belli
enfolded
New Writeups
Scaevola
Roman marriage(thing)
rootbeer277
m&m's Ice Cream Treats(review)
Transitional Man
Gus's Chalet(review)
minnow
.410 bore(thing)
shaogo
Phonautogram(thing)
Morkel
Changing your sexuality(idea)
teleny
Baron Samedi(person)
Ouzo
The Great Barbershop Race Wars(log)
Mannerisky
second language(essay)
aneurin
British Monomarks(idea)
FrankThomas
How and why do we (humans) have culture?(essay)
lee_cad
Isaac(person)
kalen
downvota(poetry)
Andrew Aguecheek
Wstfgl(thing)
ncc05
overheard at IHOP(event)
Everything 2 is brought to you by the letter C and The Everything Development Company