nLab Freyd category




A Freyd category is one way to axiomatize models of call-by-value? programming languages. It abstracts the structure of the Kleisli category of a monad, consisting of a category 𝕍\mathbb{V} that models values and another category with the same objects β„‚\mathbb{C} that models computations.

Freyd categories thus provide a categorical semantics for typed programming languages with side effects such as memory access or printing. This is in the spirit of the discussion at relation between type theory and category theory, except that page is for non-side-effecting languages. The types of the programming language are interpreted as objects of the categories. A typed term (i.e., program expression) Ξ“βŠ’t:X\Gamma\vdash t \colon X is interpreted as a morphism Ξ“β†’X\Gamma \to X in β„‚\mathbb{C}. Among the terms, it is often very important to identify those that are β€œvalues”, which in particular have no side effects, and these are interpreted as morphisms in 𝕍\mathbb{V}. Freyd categories are based around premonoidal categories, which captures the fact that reordering the execution of side effects is often subtle.

Freyd categories resolve the following complaint about using monads and Kleisli categories to model impure effects in programming languages. The Kleisli category for a monad presumes the existence of some slightly higher-order types, since if XX is an object then so is T(X)T(X), and yet it is surely possible to understand the nature of effectful computation without also assuming the existence of certain types. Freyd categories make sense even for purely first order programming languages, and the object T(X)T(X), if it exists, has a universal property, thus decoupling this relationship.


A Freyd category (following Levy 04) may be defined as

An alternative but equivalent definition is as follows (following Power, Thielecke):

A Freyd category is given by

  • a category 𝕍\mathbb{V} with finite products;
  • a symmetric premonoidal category β„‚\mathbb{C}, that has the same objects as 𝕍\mathbb{V};
  • an identity-on-objects functor J:𝕍→ℂJ: \mathbb{V} \to \mathbb{C} strictly preserving symmetric premonoidal structure, whose image lies in the centre of β„‚\mathbb{C}.

These definitions arguably violate the principle of equivalence, because they use an identity-on-objects functor in the definitions. That is, if 𝕍\mathbb{V} is equivalent to some 𝕍′\mathbb{V}', and β„‚\mathbb{C} is equivalent to some β„‚β€²\mathbb{C}', while J:𝕍→ℂJ: \mathbb{V} \to \mathbb{C} is a Freyd category, there may be no way to make a Freyd category 𝕍′→ℂ′\mathbb{V}' \to \mathbb{C}'. A resolution of this is to regard a Freyd category as a single structure, with one set of objects, two sets of morphisms, and so on; see identity-on-objects functor and M-category for further discussion.


Relation to strong monads.

If TT is a strong monad on a category 𝕍\mathbb{V} with finite products, then the Kleisli category of TT forms a Freyd category and JJ has a right adjoint.

Conversely, if (𝕍,β„‚,J)(\mathbb{V},\mathbb{C},J) is a Freyd category and JJ has a right adjoint RR, then the Freyd category arises as the Kleisli category of the monad RJRJ.

In more detail, the passage from a strong monad to a Freyd category is as follows. If TT is a strong monad on a category 𝕍\mathbb{V} with finite products, then the Kleisli category β„‚\mathbb{C} has a premonoidal structure given by XβŠ—Y=XΓ—YX\otimes Y=X\times Y on objects and where for a morphism f:Yβ†’Zf:Y\to Z in β„‚\mathbb{C} (i.e. f:Yβ†’T(Z)f:Y\to T(Z) in 𝕍\mathbb{V}) then the right tensor (Xβ‹Šf):XβŠ—Yβ†’XβŠ—Z(X\rtimes f):X\otimes Y\to X\otimes Z is given by the composite XΓ—Yβ†’fXΓ—T(Z)β†’strT(XΓ—Z)X\times Y\xrightarrow f X\times T(Z) \xrightarrow {\mathrm{str}} T(X\times Z) in 𝕍\mathbb{V}. The left tensor (f⋉X):YβŠ—Xβ†’ZβŠ—X(f\ltimes X):Y\otimes X\to Z\otimes X is given by the composite YΓ—Xβ†’fT(Z)Γ—Xβ†’strT(ZΓ—X)Y\times X\xrightarrow f T(Z)\times X \xrightarrow {\mathrm{str}} T(Z\times X) in 𝕍\mathbb{V}. This is a premonoidal structure, and it is monoidal if and only if the monad TT is a commutative monad.

Relation to Lawvere theories and PROPs

To give a small Freyd category is to give an enriched Lawvere theory relative to the empty sound doctrine where the enriching category is cartesian closed.

For example, if (FinSet op→𝕋\mathrm{FinSet}^{\mathrm{op}}\to \mathbb{T}) is an ordinary Lawvere theory, then its dual (FinSet→𝕋 op\mathrm{FinSet}\to \mathbb{T}^{\mathrm{op}}) is a Freyd category.

The Lawvere theory is commutative if and only if the premonoidal category 𝕋 op\mathbb{T}^{\mathrm{op}} is in fact monoidal.

A minor generalization of Freyd category allows 𝕍\mathbb{V} to be symmetric monoidal rather than cartesian monoidal. Then a commutative Freyd category FinSet bijβ†’β„‚\mathrm{FinSet}_{\mathrm{bij}}\to \mathbb{C} is the same thing as a PROP.

Relation to monads on presheaf categories

This relates to the situation with monads as follows. If TT is a strong monad on the presheaf category 𝕍^\hat{\mathbb{V}} then the Kleisli category 𝕍^β†’(𝕍^) T\hat{\mathbb{V}}\to (\hat{\mathbb{V}})^T is a Freyd category. But also the identity-on-objects/full-and-faithful factorization of the composite 𝕍→𝕍^β†’(𝕍^) T\mathbb{V}\to \hat{\mathbb{V}}\to (\hat{\mathbb{V}})^T yields a Freyd category over 𝕍\mathbb{V}.

Every Freyd category arises in this way, giving a correspondence between colimit-preserving strong monads on 𝕍^\hat{\mathbb{V}} and Freyd categories over a category 𝕍\mathbb{V} with products.

On the other hand, a colimit-preserving monad on 𝕍^\hat{\mathbb{V}} is the same thing as a monad in the category of profunctors whose carrier is 𝕍\mathbb{V}. But this is the same thing as an identity on objects functor 𝕍→ℂ\mathbb{V}\to\mathbb{C}. And this is a Freyd category if and only if the monad is strong.


Freyd categories were first used in

  • John Power and Hayo Thielecke β€œEnvironments, Continuation Semantics andΒ Indexed Categories”, Theoretical Aspects of Computer Software, Third International Symposium, TACS β€˜97

and named Freyd categories in

  • John Power and Hayo Thielecke, β€œClosed Freyd- and ΞΊ\kappa-Categories”, Automata, Languages and Programming, 26th International Colloquium, ICALP’99

and the longer journal version of that paper has more discussion:

  • Paul Blain Levy, John Power and Hayo Thielecke, β€œModelling environments in call-by-value programming languages”, Inf. Comput. 185(2): 182-210, 2003 preprint pdf.

The definition with monoidal actions appears in

  • Paul Blain Levy, β€œCall-by-Push-Value. A Functional/Imperative Synthesis,” Semantic Structures in Computation 2, Springer, 2004; appendix B*

The idea of extending Freyd categories to monads on presheaf categories appears in

  • John Power, β€œGeneric models for computational effects”, Theor. Comput. Sci. 364(2): 254-269 (2006)

This also contains the observation that enriched Lawvere theories are examples of Freyd categories, but the precise correspondence between the concepts is given in

  • Sam Staton, 2014. Freyd categories are Enriched Lawvere Theories. Electronic Notes in Theoretical Computer Science, Proceedings of the Workshop on Algebra, Coalgebra and Topology (WACT 2013) 303, 197–206. doi:10.1016/j.entcs.2014.02.010 (free).

The connection with monads in the category of profunctors is discussed in


  • Kazuyuki Asada. β€œArrows are strong monads”. Proceedings of MSFP β€˜10. preprint pdf

  1. Having the same objects is required or implied by having an identity-on-objects functor from 𝕍\mathbb{V} to β„‚\mathbb{C}. ↩

Last revised on August 29, 2022 at 05:31:10. See the history of this page for a list of all contributions to it.