arXiv:2608.27180cs.PLAug 2026

Manuscript Offprint

arXiv:2608.27180

You may implement this later: Cofunctors as partial implementations

Vincent Wang-Maścianica

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

A functor is a familiar model of an implementation, where every operation in a specification is assigned a concrete instantiation at the outset. But some tasks are less eager: we often want to assemble systems while leaving backend choices such as data representations and algorithms for later. We observe that cofunctors admit a direct reading as such partial implementations, which are implementations whose extra argument is a state-dependent family of deferred choices. While cofunctors (also called retrofunctors) are not novel, their conceptual and purposive reading in this manner appears to be.

1 Implement now, or later?

Suppose we have a small language of storage components. At the abstract level we want to write

Store →persist\xrightarrow{\text{persist}} PersistentStore →replicate\xrightarrow{\text{replicate}} ReplicatedStore

without immediately deciding whether persistence is provided by SQLite, a remote service, or something else; whether values are serialised as JSON or binary; or which replication protocol is used. This is ordinary software engineering, where closely related ideas are often called staged configuration: configuration decisions can be made at different stages, and later choices may depend on earlier ones [5].

Module systems allow implementations to be parameterised and instantiated later [12]; Standard ML terminology famously and confusingly calls such parameterised modules functors. A categorical functor F:S⟶CF: \mathcal{S} \longrightarrow C is naturally read as an eager implementation of a specification category S\mathcal{S} in a category of concrete programs CC, where every object AA already has an implementation FAFA, and every operation f:A→Bf: A \to B already has a chosen implementation Ff:FA→FBFf: FA \to FB. Ordinary parameterisation of the ML sort relaxes this to something like F:S×P⟶CF: \mathcal{S} \times P \longrightarrow C, where one supplies a global parameter p:Pp: P to obtain an implementation.

The interesting case we consider is when a single global parameter type P is not the right shape. For example, the available implementation choices may depend on where we are in the specification, where composition may settle old choices and introduce new ones. In the case of the store above, choosing persistence may introduce a serialisation choice, and then choosing replication may add a transaction requirement which the earlier backend either satisfies or exposes as a conflict.

Figure

© 2026 Copyright held by the owner/author(s).

This work is licensed under a Creative Commons Attribution 4.0 International License.

DRAFT PAPER UNDER REVIEW

Vincent Wang-Maścianica