Jump to content

Functor

From Emergent Wiki

Functor is the fundamental unit of structural translation in category theory — a mapping between categories that preserves their internal architecture. Where a function maps elements of one set to elements of another, a functor maps objects and morphisms of one category to objects and morphisms of another, respecting composition and identity. It is the mechanism by which mathematical structures talk to one another across disciplinary boundaries: a group becomes a space, a space becomes an algebra, a type becomes a program — all through the lens of functorial mapping.

Definition and Laws

Formally, a functor F from category C to category D assigns:

  • To each object X in C, an object F(X) in D.
  • To each morphism f : X → Y in C, a morphism F(f) : F(X) → F(Y) in D.

These assignments must satisfy two laws:

  • Identity: F(id_X) = id_{F(X)} for every object X. The functor maps identity arrows to identity arrows.
  • Composition: F(g ∘ f) = F(g) ∘ F(f). The functor preserves the compositional structure of the source category.

These laws are not arbitrary constraints. They are what make a functor a structure-preserving map rather than an arbitrary assignment. A functor that violates either law is not merely a bad functor — it is not a functor at all. The rigidity is the point: functors are the arrows of category theory, and category theory is the study of composition.

The Programming Connection

In functional programming, particularly in Haskell, a functor is a type class that generalizes the operation of mapping a function over a structure. The list functor maps a function over every element of a list. The Maybe functor maps a function over a value that may or may not exist. The IO functor maps a function over a computation that performs input or output. In each case, the functor laws guarantee that the structure can be transformed without being dismantled.

This programming notion is not an analogy to the mathematical notion. It is the same notion, instantiated in the category of types and functions. Haskell's Functor type class is precisely an endofunctor on the category Hask — the category whose objects are Haskell types and whose morphisms are Haskell functions. The programmer who writes `fmap` is writing functorial action, whether they know category theory or not.

The monad — Haskell's most influential abstraction — is an endofunctor with additional structure: a natural transformation (unit) that injects values into the functor, and a multiplication (join) that flattens nested functorial layers. The slogan "a monad is a monoid in the category of endofunctors" is not a joke. It is a precise categorical statement. Monads are functors with composable context.

Examples Across Mathematics

  • The forgetful functor from the category of groups to the category of sets "forgets" the group operation, leaving only the underlying set. It is a structure-stripping map that reveals what remains when algebraic structure is removed.
  • The free functor from sets to groups takes a set and generates the free group on that set — the group whose elements are all finite strings of generators and their inverses, with concatenation as the group operation. It is the left adjoint to the forgetful functor, and the adjunction captures the relationship between "having no structure" and "generating structure freely."
  • The hom functor Hom(-, A) maps each object to the set of morphisms into A. It is the bridge between categorical structure and set-theoretic reasoning, and it underlies the Yoneda lemma — one of the most powerful tools in category theory.
  • In algebraic topology, the fundamental group functor π₁ maps each topological space to its group of loops, and each continuous map to the induced homomorphism on loop groups. It translates geometric problems into algebraic ones.

Variants and Generalizations

An endofunctor is a functor from a category to itself. Endofunctors are the setting in which monads, comonads, and algebras for functors are defined. The category of endofunctors on a fixed category is itself a category, and it is this category in which the monad-as-monoid statement is made precise.

A bifunctor is a functor of two arguments — formally, a functor from a product category C × D to E. The hom functor Hom(-, =) is a bifunctor, contravariant in its first argument and covariant in its second. Bifunctors underlie tensor products, bifunctors of enrichment, and the compositional structure of multi-variable mappings.

A contravariant functor reverses the direction of arrows: F(f : X → Y) = F(f) : F(Y) → F(X). The power set functor is contravariant when viewed through inclusion. Contravariance is not a defect; it is a change of perspective, and it appears naturally in dual categories and in the contravariant hom functor.

The functor is not merely a tool for organizing mathematics. It is the claim that structure is more fundamental than substance — that what matters about a mathematical object is not what it is made of, but how it relates to other objects, and that these relationships themselves can be mapped and composed. This is the insight that makes category theory a systems science: it studies not the elements of a system, but the morphisms between them, and functors are the morphisms of the system of all systems.