The behaviour and interaction of finite limits (products, pullbacks and equalisers) and colimits (coproducts and coequalisers) in the category of sets is illustrated in a "hands on" way by giving the interpretation of a simple imperative language in terms of partial functions between sets of states. We show that the interpretation is a least fixed point and satisfies the usual proof rule for loop invariants.This
The languageWe shall interpret a language with the following command s in a category:Clearly skip and sequencing (;) correspond to identity and composition, so each command is a morphism, but what are the objects which serve as its source and target?Each command of a program has a "compile-time" as well as its run-time effect: here just the declaration (let) and un-declaration (discard) of variables. Before the command (in the text) there is a certain collection Γ of variables which are in scope, so in particular they may be used in forming expressions. At the end the scope, ∆, consists of Γ, plus the newly declared variable(s), minus those which have been discarded. Γ and ∆ are the source and target respectively of the morphism representing the command; by construction the source of one command is the target of the previous one, as it must be for composition to be defined.
1We do not require scopes to be nested, instead adopting the rule that if a variable name is in scope then it may not be the subject of a definition. This apparently weak convention is convenient because it allows assignment to be defined in terms of the other commands:x := a is the same as let x = a ; discard x ; let x = x ; discard x where x is a new variable, i.e. not in scope. In programming discard is, apart from this, redundant (provably so in a certain sense in our formal language) but it has been added for an exact match with the categorical concept (products) which is being used to interpret the language. Abstractly we have already said enough about the objects: they are lists of variables. (Similarly we have also given the morphisms as programs, but we shall see that we must impose an equivalence relation on them.) Variables are typed: we need the Boolean type 2 (with its elements yes and no), but shall not introduce any (other) type constructors.Concretely, a type is the set of values which may be taken by a variable to which it is attributed. The state of the machine is determined by the tuple of current values of the variables in scope, and so the object [[Γ]] representing the scope Γ is the product of (the sets interpreting) the types. In particular,and we writex :To say what expressions are, we need a language of algebraic operations.The categorical interpretation of algebra is very well known. Each operator f and constant c has an intended meaning as a morphism f : Y 1 × · · · × Y m → Z or c : 1 → Z in the category, Y and Z being the argument and result types.In the scope Γ ≡ [x 1 : X 1 , . . . , x n : X n ], expressions are interpreted assimilarly interpret the declaration and un-declaration commands.The foll...