Profunctors are categories

Here we use the context of Definition 1. (or, equivalently, of Definition 2.) of page ‘Many Faces of a Profunctor’, that is, we identify a profunctor F:\ct A^{op}\times\ct B\to \Set (according to Definition 3.) with the category \ct F that disjointly contains (isomorphic copies of) \ct A and \ct B and for all objects a\in Ob\ct A,\ b\in Ob\ct B, the set F(a,b) is considered as the homset \ct F(a\ig b) and its elements are called heteromorphisms. Their compositions with arrows of \ct A (from the left) and arrows of \ct B (from the right) are given by the action of the functor F on the arrows.
This setup naturally induces a functor p:\ct F\to\bf 2 where \bf 2 is the category of two objects 0,1 and a single nonidentity arrow 0\to 1 whose preimage at p is exactly the collection of all heteromorphisms in \ct F.
In this setting we write \ct F:\ct A\ag\ct B to express that \ct F is a profunctor from category \ct A to category \ct B.

Definition. Let \ct F and \ct G be profunctors \ct A\ag\ct B. By a profunctor morphism \teta:\ct F\to\ct G we simply mean a functor \ct F\to\ct G such that both of its restrictions, to \ct A and to \ct B, are the identity functors.

Note that such a functor \teta indeed straightly corresponds to a natural transformation F\to G where F,G:\ct A^{op}\times\ct B\to \Set are F(a,b):=\ct F(a\ig b),\ G(a,b):=\ct G(a\ig b).

Definition. A given profunctor \ct F:\ct A\ag\ct B is said to be generated by a class {\it F}_0 of heteromorphisms if every heteromorphism f can be written in the form f = \alpha\,f_0\,\beta for some \alpha\in \ct A,\ f_0\in {\it F}_0,\ \beta\in\ct B.

Definition. Let \ct F:\ct A\ag\ct B and \ct G:\ct B\ag\ct C be profunctors. Their profunctor composition \ct F\ct G is the profunctor \ct A\ag\ct C whose heteromorphisms are formal compositions (i.e. ordered pairs) (f,g) of consecutive heteromorphisms f\in\ct F and g\in\ct G, subject to the (tensor-like) relation that (f\beta,\,g) is considered equal to (f,\,\beta g) for any configuration a\fl f\to b \fl\beta\to b'\fl g\to c.

This is basically the free composition of \ct F and \ct G, and we can actually relax it in the spirit of Definition 2.
For that, let \bf 3 denote the preorder category of the three element ordered set \{0,1,2\}, i.e. it has three objects: 0,1,2 and three nonidentity arrows: {\bf a}_0: 0\to 1,\ {\bf a}_1:1\to 2 and their composition 0\to 2.

Definition. Let \ct F:\ct A\ag\ct B and \ct G:\ct B\ag\ct C be profunctors with p:\ct F\to \bf 2 and q:\ct G\to\bf 2. We call a category \ct U equipped with a functor t:\ct U\to \bf 3, a (realized) ternary composition of \ct F and \ct G, if the preimage of {\bf a}_0 at t is \ct F and the preimage of {\bf a}_1 at t is \ct G.
(Naturally, this condition can be easily rephrased using pullbacks for expressing the preimages.)

Theorem. For fixed profunctors \ct F:\ct A\ag\ct B and \ct G:\ct B\ag\ct C, there is a correspondence between their ternary compositions and profunctor morphisms of the form \ct F\ct G\to \ct H where \ct H is any profunctor \ct A\ag\ct C.

Proof. For a given ternary composition t:\ct U\to\bf 3 we can define \ct H by simply deleting \ct B (=t^{-1}(1)) from \ct U and map the formal composition (f,g) of consecutive heteromorphisms f\in\ct F,\ g\in\ct G to their actual composition fg defined in \ct U.
For a given profunctor morphism \tau:\ct F\ct G\to\ct H we can define the category \ct U as basically the union of \ct F,\ct G and \ct H such that the composition of consecutive heteromorphisms f,g is defined to be (f,g)^\tau.

Corollary. We could have defined the composition \ct F\ct G of profunctors \ct F:\ct A\ag\ct B,\ \ct G:\ct B\ag\ct C as the initial object in the category of their ternary compositions.