# Functor

### From Conservapedia

The term **functor** has two distinct meanings.

## In Pure Mathematics

In category theory, a **functor** is a map between categories satisfying certain relations. Functors can be thought of as expressing relations between categories, and have a wide range of applications. For example, given a problem about topological spaces, one might apply some functor (say, taking the homology groups), and obtain an equivalent problem about vector spaces. Since problems about vector spaces are generally much easier to answer than those about general topological spaces, this may make it easier to understand the original problem.

Functors, in a sense, provide for categories what group homomorphisms do for groups. To be precise, a function between two categories associates to each object an object , and to each morphism a morphism such that:

- .

Functors are the fundamental objects used to relate structures between different categories.

The traditional terminology for the above is a "covariant functor", to distinguish it from "contravariant functors", which reverse the direction of compositions, and instead satisfy

- .

We will see an example of this below.

### Examples

Algebraic topology was the first field in which the usefulness of the notion of a functor was recognized. A basic example is the fundamental group functor . The action on objects is defined by sending a topological space to its fundamental group π_{1}(*X*). Recall that a map between two topological spaces induces a map by . Set so defined. The functoriality of π_{1} boils down to the fact that , that is, the identity map on a topological space induces the identity map on its fundamental group, together with the fact that , explained at fundamental group.

A simple example arises in the category of vector spaces. Fix a vector space *V*. We can define a functor by

- An object
*A*(that is a vector space) is sent to Hom(*V*,*A*), the vector space of linear maps from*V*to*A*. We can think of these linear maps as matrices. - A linear transformation (i.e., an element of is sent to a linear transformation by setting . I other words, the image of φ is supposed to be a linear transformation from Hom(
*V*,*A*) to Hom(*V*,*B*): it is defined by sending a linear transformation to .

We can similarly obtain a contravariant function Hom( − ,*V*) by

- An object
*A*is sent to the vector space of linear maps Hom(*A*,*V*). - A map is sent to a linear map by . Given a linear map from B to V, we get one from A to V by composing with φ. Note that morphisms now compose in the opposite direction: that is why this is a contravariant functor.

## In Computer Science

In computer science, the term "functor" is short for "function operator", also called a "function object". It is essentially a class method with no name. Many modern programming languages support this. For example, in C++ one can define a function object with the "operator()" notation, that is, a definition of what parentheses mean after an object.

class C { public: int operator()(int i, int j) { return k+i*j; } int k; ..... }; ..... C MyObject; MyObject.k = 3; int r = MyObject(4,5); .....

We have effectively defined a nameless method for class C. Instead of making a named invocation like "MyObject.func(4,5)", we just write "MyObject(4,5)".