Manuscript Offprint
arXiv:2608.21271Finitary Semantics for Full Ground Local State
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
ORPHEAS VAN ROOIJ, University of Edinburgh, UK
OHAD KAMMAR, University of Edinburgh, UK
SAM LINDLEY, University of Edinburgh, UK
CRISTINA MATACHE, University of Birmingham, UK
Full ground local state (FGLS) refers to dynamically allocated mutable state that allows storing ground values and references. It is a key ingredient in many imperative algorithms as it enables (cyclic) data structures. In this work, we treat full ground local state as a computational effect, focusing on one particular denotational model: Kammar et al.'s possible worlds monad on sets indexed over sets of locations.
We resolve an outstanding question regarding this FGLS monad: is it finitary? We show that the FGLS monad is not finitary by showing the existence of non-finitary computations in the monad. We then introduce a finitary submonad of Kammar et al.'s monad, give it a concrete description and show that it provides an adequate semantics for FGLS. The submonad we construct paves the way to understanding FGLS in the future via an equational axiomatization suitable for program reasoning.
CCS Concepts: • Theory of computation → Denotational semantics; Abstraction.
Additional Key Words and Phrases: local state, monads, observational equivalence, denotational semantics, computational effects, categorical semantics
1 Introduction
A ubiquitous feature of imperative programs is access to dynamically allocated mutable state: reference-based memory that permits allocation of new memory cells, as well as reading and writing from existing ones. Dynamic allocation of mutable memory is often called local state since allocated memory can only be accessed from those parts of the program that were passed the reference. In the case of full ground local state (FGLS), cells may store ground values (e.g., booleans, integers) and references, enabling us to represent imperative data structures such as cyclic linked lists. Crucially, full ground local state forbids storing functions which introduce general recursion through Landin's knot [20].
Various models for local state exist in the literature which include among others relational models built via logical relations on nominal-cpos [7, 11], step-indexed syntactic logical relations [3, 9], game semantic models [1, 19, 25], as well as monad semantics based on possible worlds [15, 24, 26].
We are concerned with possible worlds semantics that model heaps and types as sets indexed over sets of locations, together with a suitable state-like monad on the appropriate category. For the ground local state case where only ground values can be stored, heaps are of a contravariant nature: we can select smaller segments of the heap by projecting out some of the cells [24, 26]. In the full ground setting this is no longer the case: projecting out a smaller heap may result in an invalid one since the references stored in the cells may now point to undefined data, i.e., they may be dangling. Kammar et al. [15] address this by equipping heaps with a covariant structure: heaps can be extended with new data modelled via a category of instantiations that carries the data. Their FGLS monad supports:
-
Effect masking: Computations that do not depend or return references are semantically equivalent to pure values.
-
Adequacy: Denotationally equal terms are observationally indistinguishable.
Authors' Contact Information: Orpheas van Rooij, University of Edinburgh, UK, orpheas.vanrooij@ed.ac.uk; Ohad Kammar, University of Edinburgh, UK, ohad.kammar@ed.ac.uk; Sam Lindley, University of Edinburgh, UK, sam.lindley@ed.ac.uk; Cristina Matache, University of Birmingham, UK, c.matache@bham.ac.uk.
0:2
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
where M, N are -terms that manipulate full ground references.
- Program Equivalences: Validates desired equations such as
where letref in allocates a new reference in with value , updates the contents of reference with and states that does not occur free in .
These properties make it a useful model for FGLS and justify using it as basis for more sophisticated stores. This paper extends the metatheory of this monad by resolving an outstanding question.
Finitary presentations of a monad. In seminal work, Moggi used monads to model computational effects such as mutable state, input/output and non-determinism. The theory of algebraic effects e.g. [4, 26] refines Moggi's programme by using algebraic theories in the sense of universal algebra to characterise computational effects equationally. In this setting, the effectful behaviour of programs is described by a set of effect operations and equations between these operations. For example, non-determinism can be described by an operation or that is commutative, associative and idempotent.
Moggi’s monads can be recovered via the well-known correspondence between monads and algebraic theories [13, 21, 29]: finitary algebraic theories correspond to finitary monads on the category of sets. An algebraic theory is finitary when it admits a presentation whose operations are of finite arity. There is no requirement that the set of operations or equations are finite.
However, when describing a computational effect, one often seeks a presentation of the algebraic theory with a small number of intuitive operations and equations, as in the non-determinism example above. The role of the presentation is to serve as a basis for programming with the effect, via the operations, and for reasoning about effectul programs via the equations.
The goal of our line of research is to find such an algebraic presentation for the full ground local state monad of Kammar et al., for which none has been discovered yet. Roughly speaking, the FGLS monad is defined on indexed sets, rather than sets, so we would need to use a more sophisticated notion of algebraic theory, rather than the classic one, to maintain the monad-theory correspondence.
Such extensions of algebraic theories and their correspondence to monads have been developed, for example: monads with arities [8], enriched Lawvere theories [28] and parameterized algebraic theories [32]. Out of these extensions, only parametrized algebraic theories admit a syntax for specifying presentations of theories, which we are particularly interested in from a programming perspective. Moreover, both enriched Lawvere theories and parameterized algebraic theories require the monad in question to be at least finitary.
Until now, the question whether the full ground local state monad of Kammar et al. is finitary remained open. In this paper, we provide a negative answer. We then characterize a finitary submonad of the FGLS monad and give it a concrete description. Therefore, the submonad we introduce opens the way to characterizing FGLS as a parameterized algebraic theory, or as an enriched Lawvere theory, in future work. The main contributions of the paper are as follows:
(i) Non-finitarity. We show that the FGLS monad is non-finitary by showing the existence of certain non-finitary computations ( 2.3). Such computations cannot be represented as terms in the programming language, and so the model has extra information which allows denotations to detect observationally undetectable differences.
(ii) Worlds, Heaps with variables and Unification. We develop the machinery needed to describe finitary FGLS computations. We introduce two-kinded worlds, heaps with variables, heap unification and matching and identify the relevant structures ( 3).
0:3
(iii) Finitary FGLS monad. Using this machinery we define a finitary FGLS submonad and show that its functor and monad structure lifts from the full monad (§ 4.3). Due to its finitary nature, this monad is more amenable to equational axiomatisations. It further enjoys adequacy of the denotational semantics with respect to the operational semantics, inherited from the non-finitary monad (§ 5).
2.1 Programming Language
We revisit the programming language , a higher-order -calculus with full ground references. The formalism of is parametrised by a set of sorts which we use to define the set of full ground types as
It includes a reference type for every sort , the empty type 0 and representing finite sums, and unit type 1 and representing finite products.
We further require an interpretation function ctype that assigns a full ground type D for every sort C. This stratification between sorts and full ground types enables us to represent potentially cyclic data structures where the recursive occurrence is guarded by a reference type.
Example 2.1. Consider Sort := {bool, boolList, nat, nat2}. The following interpretation for bool, boolList represents boxed boolean valued linked lists:
and for nat represents boxed natural numbers and nat2 are boxed pairs of boxed natural numbers:
Worlds. Pointers to memory cells are called locations ranging over a countable set , and finite sets of locations with an associated sort are called worlds. Formally, a world is a partial function with finite support. The finite support of is denoted by . We write worlds as , to really mean its support is and satisfies . We write for the cardinality of , which is in this case, and we order worlds by inclusion: . Lastly, by convention, when enumerating locations we assume that they are all distinct.
Syntax. is a coarse-grained call-by-value language with the usual -calculus constructs for finite sums and products. Figure 1 gives the syntax of where the shaded constructs relate to references. The types of are the full ground types closed under the function type constructor, thus full ground types are a subset of all types. Values include variables and -abstractions, location literals which are pointers to allocated memory cells as above, as well as the unit, binary pairs and injections. Expressions consist of the usual constructs: values, application, pairs over expressions, pair eliminator split as . , injections over expressions, falsity eliminator case , and sum eliminator case . For references, performs equality testing between two references, ! reads a reference, writes value of to reference , and letref in allocates references with the corresponding values and makes them available to .
We introduce the following sugar: with , , , and where does not occur free in .
Typing judgments for values and for expressions are parametrised by a world that represents the allocated locations. This parameter is used in (Loc) to ensure that locations are present in the prescribed world. The type system is monotone on world extensions
0:4
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
(Reference and ×, +, → types)
(λ-calculus, and location literals)
(Products)
(Sums)
(Values and Application)
(Products)
(Sums)
(References)
Fig. 1. Syntax of
, thus rule (WorldExt) is admissible. The interpretation function ctype is used in (Read), (Write) to obtain the full ground type associated with the sort. Equality testing (Eq) expects two expressions with reference types. Allocation (Alloc) performs simultaneous recursive allocation, that is, makes the references to be allocated available in the instantiation data. This allows the creation of mutually cyclic data structures.
Fig. 2. Typing rules of regarding references
Example 2.2. Creates a cyclic list with one node with the associated heap given on the right

Operational Semantics. An (untyped) heap is a partial function , and a configuration consists of an expression and a heap . The operational semantics of is given in big-step, , which relates configurations on expressions with configurations on values. Figure 3 gives the rules related to references.
(Red-Read) evaluates M to a location l and returns its value provided the resulting heap defines l. (Red-Write) evaluates from left to right, reducing M and N to a location l and new value W and updates the heap l with the new value. (Red-Eq) evaluates left to right, reducing M and N to locations , and returns whether they are equal . Function interprets boolean b from the metalevel to syntax. Rule (Red-Alloc) generates distinct fresh locations , and evaluates the body M with the updated heap after substituting the new locations.
0:5
(RED-ALLOC)
Fig. 3. Reduction rules of for references
Well typed terms in are sound and total: a closed well-typed term evaluated with a compatible heap reduces to a closed value. We refer the reader to [15] for the full specification of which we include in the appendix for completeness § A.1.
2.2 Full Ground Local State Monad
We assume familiarity with categories, functors and natural transformations, and explain any further concepts as needed. For a small category C, we denote the category of its set-valued functors as , and let be the covariant hom functor, i.e., is the set of all morphisms with domain and codomain in .
The category has the worlds for objects, and morphisms are world extensions with renamings: is an injective function between their supports that preserve the sorts. That is, for every location , we have . Further, let be the world of all locations in that are not hit by : , and let be the inclusion.
Heaplets and Heaps. Closed full ground values are modelled semantically as elements , where is an indexed set over worlds i.e., a functor in . The monotonicity of the type system with respect to world extensions (WorldExt) is modelled by the covariant structure of functors . A world extension is a morphism in , and thus the functional action on morphisms takes a and extends it to . Reference types are interpreted using the hom-functor , and thus is a morphism in , i.e., a selection of a single C-sorted location in .
The heaplet functor represents heap segments with defined locations.
Values in a heaplet have access to a possibly bigger world , enabling local level reasoning in a spirit similar to separation logic. The heaplet functor is contravariant on world (we can project out a smaller heaplet), and covariant on world (by the covariant structure of semantic values).
Example 2.3. Consider world extensions and . Applying them to heaplet results in:
0:6
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache

We equip W with data using heaplets to form the category WII. Objects in WII are worlds, and morphisms consist of a morphism in W and a heaplet . Thus defines a value for every location that is not hit by , with the value having access to the bigger world. Composition of morphisms in WII is further described in § 3.1, and we have a forgetful functor .
The heap functor represents fully defined heaplets, given on worlds as:
The functional action on morphisms extends a heap with a heaplet , giving a covariant structure to full-ground heaps.
Example 2.4. We form morphism in using the heaplet from Example 2.3, . Applying to heap given below results in a heap where locations are not reachable from .

heap
heaplet
heap
Stateful Values. In the setting of local state, return values are not necessarily pure. They may return an existing or newly allocated reference, and are therefore understood in the context of a world, i.e., a heap layout. Accordingly, stateful values are an abstraction over return values that additionally track the allocations that occurred and the resulting state of the heap.
Semantically, stateful values are given via a W-action on WI and a monad on WI shown in Figure 4. Functor represents indexed sets of pairs over worlds: it lifts to WI using the forgetful functor and takes the cartesian product in WI, . Monad on the other hand models allocation with garbage collection capabilities.
For a return type , and world representing the existing heap layout, a stateful value allocates locations, returns value and updates the heap to . These stateful values are viewed only up to observable allocations, thus modelling garbage collection.
Example 2.5. All four stateful values are over public world with return value:

Only the middle two stateful values are equal because allocations , is not observable: they are not returned nor are they reachable from , and are therefore garbage collected. In contrast, the left-most stateful value stores at and in the right-most, allocation is observable from .
Intuitively, unit injects into a context with no allocations and bind composes the allocations.
0:7
Fig. 4. State-transformer description of the FGLS Monad
The Monad. Action has a right adjoint by generalities, inducing a state transformer over full ground heaps (Figure 4). We think of as lifting the exponential in WI to W. More concretely, at world w it is equivalent to:
Specialising this adjunction to stateful values gives us the function-like structure of T:
Therefore, a FGLS computation is a natural transformation : defines a stateful value for every and heap . Naturality says that must only examine the reachable parts of the heap starting from world : different unreachable heap segments should not be observable. Finally, the monad structure of is given by the monad and curry/uncurry:
is a computation that returns leaving the heap unchanged (no allocations occur), and first evaluates and calls with its result value and the modified heap.
We note in passing, that the FGLS monad is equivalently given using an End:
where is the comma category over world and forgetful functor .
2.3 Non Finitariness of FGLS Monad
As explained in the introduction, one of the long-term goals of our work is finding an equational characterization of FGLS via a suitable notion of algebraic theory. To be able to use the framework of parameterized algebraic theories [32] for this purpose, which provides a syntax for presenting theories, or that of enriched Lawvere theories [28], we would require the FGLS monad to be finitary. In this section we discuss what being finitary means and why the FGLS monad does not satisfy this requirement.
We explain what it means for a monad to be finitary through the simpler setting of the global state monad on Set. Let be a set that represents the state, which may be a single ground value cell (e.g., ), or an entire heap (e.g., ). The global state monad is given as , which represents state transforming functions with return values of type .
When is finite, the global state monad is finitary. For instance, can be equivalently described via an algebraic theory that has operations , , where selects continuation or according to the contents of the cell, and updates the value of the store. However for non-finite , is not finitary: get would need a countable arity to represent state . Put differently, is finitary if for every , has finite image [18].
To motivate why finitariness fails for the FGLS monad, consider representing the heaps from § 2.1. The global state monad is not finitary for the same reasons as above:
0:8
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
there exists a function . that counts the number of defined locations and has a countable image.
We define an analogous function in the FGLS setting, called heapSize. First let the result type be pure N values given by the constant functor . We define heapSize at world representing a single public location of sort nat pointing to the heap.
Recall from (§ 2.2), to give heapSize ∈ T(Δ_N)(l : N) is to give a natural transformation W(l : nat, −) ⊙ H → P(Δ_N ⊙ H), where naturality says that heapSize must only examine the reachable parts of the heap starting from l. Therefore, we define heapSize at (l : nat) → w, and heap η : H(w) by traversing η starting from σ(l) and returning η^P ⟨n, η⟩ where n is the number of distinct locations it has encountered. For instance heapSize returns for the following heaps:



heapSize(l) = 1
heapSize(l) = 2
heapSize(l) = 2
Since is finite, heapSize is well-founded. With this example we will show that the FGLS monad is not finitary as it returns countably-many different values according to the heap it is applied to. We refer the reader to (Lemma A.1) for the formal definition of heapSize.
We note that even though finitariness for the FGLS monad may seem restrictive as it places bounds on heap traversals, a programming language that supports complete heap traversals while remaining in the realm of terminating languages is also strange. One might imagine introducing heapSize as a built-in operation in the language but that operation either exposes unnecessary lower level details about the runtime or requires an expensive garbage collection operation.
In the next section, and in §4, we develop a finitary version of the monad that can in the future be used as a basis for an equational axiomatization of FGLS. We construct our finitary monad by removing non-finitary computations such as heapSize from the original monad.
2.4 Finitary FGLS Monad
The central idea behind finitary computations is that they return finitely many values. Applying this to the FGLS setting means that it cannot return a different value for every possible heap. We therefore represent a finitary FGLS computation by finitely partitioning the heap space into segments and assigning a stateful value to each segment. We begin by elaborating on the idea of finite partitions of the heap space.
Templates are two-kinded worlds: one kind for concrete locations and another for location variables. While concrete locations represent cells with defined data, location variables are extension points which we can instantiate to extend the heap. We write templates as , where metavariable ranges over templates, over concrete locations and over location variables. We write for the world with only concrete locations and for the world with only the variables. We further write for the template seen as a world, that is, we forget the distinction given by the two kinds.
Stencils represent collections of heaps with a common set of public locations. That is, for a public world w and template , a stencil is a pair , with giving the mapping of the public locations and heaplet the possibly incomplete segment of the heap. We equip stencils with a covariant structure that extends the heap by instantiating variables . Thus, a stencil can be thought of as a collection of concrete heaps given by all its extensions.
Example 2.6. We define three stencils all over public world (l : nat):
Not all interpretation functions yield a non-finitary FGLS monad, but examples of interest that support cyclic data structures will be non-finitary.
0:9



stencil
stencil
stencil
Stencil represents heaps that are defined on at least two locations and have (inr•) stored in l, e.g., the first three heaps below are valid extensions whereas the right-most is not.




A stencil is said to be connected if every location can be reached by traversing the heaplet starting from a public location. In the above example, stencils , are connected, whereas is not because is not reachable from .
For a finite set of templates , we call a -indexed family of stencils over a public world w a cover. We refer to connected covers if all its stencils are connected, non-overlapping covers if the collections of heaps represented by the stencils are disjoint and complete covers if every heap is included by exactly one stencil in the cover. Completeness of a cover implies that it is both connected and non-overlapping.
Example 2.7. The cover over public world is complete since every heap with a public location will store in it either (covered by ) or (covered by ). On the other hand, the cover , is not complete since it is neither connected (due to ) nor is it non-overlapping: heap from Example 2.5 is included by both and .
A complete cover is thus a finite partition of the heap space over a common set of public locations. § 3 introduces templates formally and in § 4.1 we assemble them to form stencils and covers.
Resultlets are a means to assign stateful values to each stencil in a cover. Since stencils represent collections of heaps via the location variables, we similarly introduce variables to stateful values and talk about collections of them.
An -valued resultlet over template is thought of as a stateful value that has access to variables . Specifically, a resultlet has the following data:
• An injection representing an allocation of locations.
• An X-valued return value that can also return variables .
• A heaplet that is defined on and has access to variables .
Notice that resultlets cannot instantiate variables in their data: these variables represent the state of the heap that is left unchanged. Just as with stencils, resultlets are thought of as collections of stateful values given by all the instantiations of .
Example 2.8. We create two -valued resultlets over templates and . Resultlet allocates a new cell , creates a cycle with and returns , whereas does not allocate any new cells but instead only writes to .


0:10
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
Recall the four stateful values from Example 2.5. Resultlet can be extended to the right-most three using data and . In contrast, cannot be extended to the left-most stateful value since is an existing location whereas has been allocated.
For a finite set of templates , we call a -indexed family of X-valued resultlets an evaluation. Resultlets and evaluations are further described in § 4.2.
Finitary Computations. We link covers with evaluations to describe the finitary FGLS computations. Every triple consisting of a finite set of templates , a -indexed complete cover over and -indexed X-valued evaluation describes a FGLS computation in in a non-unique way.
For instance, represents a finitary FGLS computation over public world and templates and . The computation that it realises is defined at , by case splitting on the contents of cell . If it is , it overwrites it with the cycle given by leaving the rest of the heap unchanged. If it is , for some location , it leaves the whole heap unchanged. In both cases is returned.
We say that is finitary if it can be expressed using covers and evaluations. In § 4.3 we show that the finitary computations are closed under the functor and monad structure and therefore define a submonad of .
3 Worlds, Templates and Instantiations
In this section we introduce the machinery needed to describe the finitary FGLS monad. We first revisit worlds and instantiations (§ 3.1) from [15] and then extend worlds to two-kinded worlds called templates (§ 3.2). We then introduce instantiation data to templates (§ 3.3) and lastly develop the theory for collections of templates with instantiation data (§ 3.4).
3.1 Worlds and Instantiations
We first revisit categories W and WII introduced in § 2.2.
Recall that category W has worlds w as objects and morphisms are sort-preserving injections . We can form the disjoint union of two worlds denoted by that has many locations. This construction extends to a functor together with injections and but note that it does not satisfy the universal property of coproducts because of injectivity of morphisms in W.
We equip W with instantiation data to form category WII, which has worlds w as objects, and morphisms consist of a sort preserving injection and heaplet
Semantic full-ground values are given for reference types using the hom-functor , and thus is a morphism in , i.e., a selection of a single C-sorted location in . The , + types are given via the cartesian closed structure of . Note that semantic values are in one-to-one correspondence with syntactic closed full ground values: .
Composition of is defined by composition of the underlying injection and composition of the instantiation data is given by
0:11
A comes either from or from , and promotes locations to .
Example 3.1. The composition of is given as

heap
heap
heap
W has pullbacks given by image intersection: .
3.2 Templates
We introduce worlds with two kinds of locations (i) concrete locations that represent pointers to allocated data and (ii) location variables that stand for extension points that hold arbitrary cell contents. These two-kinded worlds, called templates, are modelled using category T given by
• Objects: A world with a chosen subset .
- Morphisms: A morphism is a sort-preserving injection that preserves the chosen subset, that is, the restriction of to factors through :
Composition is given by composition of the underlying injection. We have two forgetful functors , , projecting the - and + components respectively: , . We use metavariable to range over objects (templates) in , and call its concrete locations, its combined locations, and its location variables. If it is clear from context, we overload and for the inclusions into . Let be the template with only concrete locations, and let represent the template with only location variables.
Every morphism induces a morphism in and every morphism in is mono, and epis are exactly the morphisms that have a surjective component. Moreover, concrete locations cannot be mapped to variables by and so concrete locations cannot become uninstantiated.
We select specific locations by intersecting the images, e.g., , refers to the variables that are instantiated by and similarly represents variables that are fresh w.r.t. are the new locations introduced by .
Let range over concrete locations, and let range over location variables. We write templates as single worlds , to really mean the template given by the inclusion .
Example 3.2. Consider the following morphism in T:
It instantiates variable from its domain, and introduces a new fresh variable .
The category T has initial object , and equalizers and pullbacks such that , preserve these. It is also equivalent to the arrow category .
0:12
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
3.2.1 Local Independent Coproducts. For a span its local independent coproduct gives the least way to close the span into a commuting square, that is, it makes the least assumptions on which locations from and are related (at both the and level). We define its local independent coproduct on the level as
are given by the canonical isomorphism of injections: . The concrete locations are
Thus we only relate locations from and and a location is concrete iff it is concrete in either or .
Example 3.3.
is a local independent coproduct square since and
are not conflated and is not instantiated.
Local independent coproducts can be given a universal property using the independence structures of [30]. A commuting square is called independent if its -image is a pullback, and a local independent coproduct square is the universal independent square, that is, every other independent square factors uniquely through it.
3.2.2 Variable Preserving Morphisms. We call morphisms in T that do not instantiate location variables from their domain as variable preserving.
Definition 3.4. A morphism is variable preserving if it satisfies .
Example 3.5. is variable preserving since remains a variable in the codomain, whereas is not.
Variable preserving morphisms are closed under composition, and characterise exactly the regular monos in T.
Lemma 3.6. Local independent coproducts reflect variable preserving morphisms, that is, in a span , if is variable preserving, then so is .
3.2.3 Variable Reflecting Morphisms. Similarly, we call a morphism that does not introduce location variables as variable reflecting.
Definition 3.7. A is variable reflecting if it satisfies .
Example 3.8. is a variable reflecting whereas is not.
Variable reflecting morphisms are closed under composition and local independent coproducts reflect them in the same manner as Lemma 3.6.
0:13
3.3 Template Instantiations
We extend templates and their morphisms with instantiation data. Let be the category with objects being templates , and morphisms are pairs consisting of a template morphism and instantiation data . defines a value that has access to all for every that is not hit by .
Composition of is defined by composition in for the underlying injection and composition of the instantiation data is given as in :
We have a forgetful functor , lifted functors , , and functor which maps to concrete templates . We further inherit the terminology of and talk about concrete locations and location variables, and talk about variable preserving and reflecting morphisms by noticing that preserves and reflects these properties. The forgetful functor preserves equalizers and pullbacks.
Definition 3.9. The template heap functor is defined as .
We have and so a template heap defines a value for every concrete location in that has access to all locations .
3.3.1 Reachability. Instantiation data introduce a notion of (un)reachable locations, referring to whether a location can be reached from a concrete location by traversing the data.
Definition 3.10. The reachable locations from w.r.t. a template heap is the least factoring of as such that for every reachable concrete location , the locations in are included in : there exists a s.t. . We refer to as the reachable and as the unreachable locations.
Example 3.11. The reachable locations from w.r.t. template heap
are , since is not reachable from .
Lemma 3.12. For every and the reachable location factoring exists.
Proof Sketch. World is given by the image and all locations encountered when traversing starting from every concrete location that is in (i.e., ).

3.3.2 Connectivity. Using reachability we identify connected morphisms in TII with the property that all locations in the codomain are reachable from locations in the domain. We define connectivity formally by giving a factorisation of morphisms in TII that splits its reachable and unreachable components.
Definition 3.13 (Factorisation in TII). For a morphism , we consider the reachable locations from w.r.t. . Let
be the factoring of with the chosen subset for being the reachable concrete locations . The property of Definition 3.10 allows us to split into data for these two morphisms.
For a morphism , we write and for its factorisation given by Definition 3.13.
0:14
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
Example 3.14. The factoring of with data
with data
A morphism is said to be connected if is an isomorphism and correspondingly, it is disconnected if is iso. We have that is itself connected, and is disconnected.
Epimorphisms in TII are exactly the connected morphisms, and regular monomorphisms are exactly the disconnected morphisms. Disconnected morphisms are alternatively characterised as the variable preserving ones. We use arrows for epis, and for regular monos.
Lemma 3.15 (Orthogonal Factorisation System in TII). The classes of epis (connected) and regular monos (disconnected) morphisms gives rise to an orthogonal factorisation system in TII.
3.3.3 Unification. Dealing with concrete cells that can store location variables naturally leads us to unification that answers the question of whether two template heaps with a common set of starting locations unify to a larger template heap that includes them both. In the case of TII, template heaps are morphisms and so we phrase unification as follows.
Definition 3.16. A span unifies if there exists a commuting square
We call a unifier of .
Example 3.17. Not all spans unify, e.g.,:
We consider a partial order on unifiers of the same span defined as
In general, a span might not have a least unifier as the following example shows.
Example 3.18. Consider the following two unifiers of the same span with the underlying T morphisms given by the indices.

The resulting heaps and are incomparable as , cannot be collapsed to a one cell.
General Unifiers. While least unifiers do not necessarily exist, there exist unifiers which we call general with the property that when taken together jointly serve as the least element.
Definition 3.19. A unifier for a span is called general if are jointly surjective and are jointly surjective.
0:15
Intuitively, a general unifier unifier does not introduce new concrete locations or variables that do not come from the span, that is, is completely determined by and vice versa.
Example 3.20. Both unifiers from Example 3.18 are most general unifiers.
The jointly surjective property of general unifiers guarantees that every unifier uniquely factors through exactly one isomorphic class of general unifiers. It also implies that for a given span, there can only be a finite number of isomorphic classes of its general unifiers.
Unification and Local Independence Coproducts. Local independent coproducts in T (see § 3.2.1), when equipped with instantiation data are themselves general unifiers.
Definition 3.21 (Local Independent General Unifiers). A unifier is called a local independent general unifier if its u image is a local independent coproduct square.
Consider a span , such that is variable preserving. Since does not instantiate any variables, the data of does not have to agree with any cells in for the morphisms to commute. As a result, the local independent general unifier exists and relates locations in and only from ones that come from .
Example 3.22. The square
from Example 3.3 equipped with data is a
local independent general unifier.
3.4 Families of Template Instantiations
The last building block required to describe the finitary monad is a means to talk about collections of template heaps related by a common set of public locations. We model these collections using the Fam(Ⅲ) construction, representing finite families of templates and their instantiations:
• Objects: A finite set , and an -indexed set of templates .
- Morphisms: A consists of a mapping and a -indexed set of morphisms
Notice that Fam(Ⅲ) is the free finite product completion of TⅢ. We have a forgetful functor that maps into the indexing sets. Let range over objects in Fam(Ⅲ) and we use list notation to write objects in Fam(Ⅲ).
Example 3.23.
give us a morphism .
Lemma 3.24. Fam(Ⅲ) has pushouts given by the general unifiers of TⅢ.
Proof Sketch. The pushout of selects the (representative) general unifiers for
every pair of matching indices . That is, for every matching pair , we have a finite number of representative general unifiers with morphisms
0:16
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
in . The pushout is then given by the pairing of all these morphisms
and , .
We further characterise collections in Fam(Ⅲ) according to how the individual morphisms in the collections interact.
Definition 3.25. A morphism is said to be connected if every is connected.
Example 3.26. The morphism from Example 3.23 is connected as both do not introduce unreachable locations.
Definition 3.27. A morphism is said to be non-overlapping if every distinct pair of morphisms with the same root, , do not unify. That is, for every s.t. :
Example 3.28. The morphism from Example 3.23 is non-overlapping since any extension of will have at whereas will have . On the other hand, adding
to the collection breaks the non-overlapping property.
Epimorphisms in Fam(Ⅲ) are exactly the connected and non-overlapping morphisms.
Definition 3.29. We say that an epi is complete if for every morphism there exists a such that
The epi property of guarantees that the induced morphisms are unique, and complete morphisms are closed under composition and are stable under pushouts.
Example 3.30. The collection is complete: a morphism is a heap with -many concrete locations and a public location given by . Since covers both possible inhabitants of , every such can be factored through either or .
4 Finitary FGLS Monad
We now connect the combinatorial machinery developed in § 3 with the goal of describing the finitary FGLS computations. The central idea is that a finitary computation can be expressed using finitely-many stateful values with variables, each assigned to one stencil in a complete cover. We first formally define stencils and covers (§ 4.1), we then define collections of stateful values using resultlets (§ 4.2), and link covers and resultlets to local state computations using realisations in (§ 4.2). We finally present the finitary monad in (§ 4.3).
0:17
4.1 Covers and Matching
We model stencils ( 2.4), that is collections of heaps with a common set of public locations as morphisms in .
Definition 4.1 (Stencil Functor).
with the obvious functional action. A stencil ?w → τ that does not have unreachable locations is said to be connected, i.e., it is a connected morphism (§ 3.3.2).
We call finite collections of stencils with a common set of public locations as covers.
Definition 4.2 (Cover). For a finite family of templates , and world , a cover cov over is an indexed family of stencils , that is, it is a morphism .
Example 4.3. from Example 3.23 is a cover over .
We inherit the terminology from § 3.4, and talk about connected, non-overlapping, complete covers, and we further describe three operations on covers: (i) hiding some public locations, (ii) rebasing over a different world and (iii) intersecting two covers.
Definition 4.4 (Hiding Locations in a Cover). For a renaming , and a cover cov over , we have a cover over by precomposition
Hiding does not preserve connectivity, non-overlapping, or completeness in general.
Definition 4.5 (Rebasing a cover). For a and cover cov over , we rebase cov to a
cover cov over using the pushout
\text{cov} \downarrow \quad \text{?}^w \xrightarrow{\text{?}^{\sigma}} \text{?}^w'
in Fam( ) (see Lemma 3.24).
Cover rebasing preserves connectivity, epimorphic covers, and completeness.
Example 4.6. Consider a singleton cover with data
and we rebase it over . The resulting cover has three stencils




Definition 4.7 (Cover Intersection). Given a cover cov over and a cover cov' over we define their intersection cov cov' as the biggest cover that is included in both of them. It is
given by the pushout
0:18 Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache Finally, we use the notion of covers to describe sorts that can be finitely enumerated. Definition 4.8 (Sort Enumeration). A cover ? a:C cov −−→ Σ is called an enumeration of C if it is complete and every covi∈ |Σ| : a : C → 𝜏i instantiates a, i.e., (a : C) ⊗[𝜏i] ⌈𝜏i⌉ = ∅. We call a sort finite if it has an enumeration and every sort that has a full ground type interpretation as in § 2.1 is finite. Example 4.9. The only enumeration of ctype zero := 0 is the empty cover (a : zero) → ∅, for ctype unit := 1 is the singleton cover (a : unit) a↦→l −−−→ [(l : unit)] with unit data. For boolList an enumeration has stencils (a : boolList) → [(l : bool), (l1 : boolList, a2 : bool), (l1 : boolList, a2 : bool, a3 : boolList)] with data given by inl ( ) l a ↦→ l , a2 ⟨•, •⟩ l1 a ↦→ l1 and a2 ⟨•, •⟩ l1 a3 a ↦→ l1 4.2 Evaluation We call morphisms that are both variable preserving and reflecting (see § 3.2.2 and 3.2.3) as allocation morphisms to model that allocation only introduces new concrete locations. Definition 4.10 (Allocation Morphisms). A morphism 𝜌 : 𝜏1 → 𝜏2 ∈ T is an allocation morphism if it is both variable preserving and reflecting, and we denote it by −→𝜈 arrow. For a 𝜌 : 𝜏1 −→𝜈 𝜏2, its variables ⌈𝜏2⌉ are exactly ⌈𝜏1⌉, and so in particular, a morphism with a concrete template as domain 1w −→𝜈 𝜏 ′ implies that its codomain is also concrete: 𝜏 ′ = 1⌊𝜏 ′ ⌋ . Allocation morphisms are reflected by local independent coproducts (as in Lemma 3.6), and further, identities are allocation morphisms and are closed under composition. Therefore, consider alloc(T) ⊆ T, the wide subcategory of T that has objects Obj(T) and only allocation morphisms between them. Let 𝜏/alloc(T) be the set of allocation morphisms with domain 𝜏 𝜏 𝜌 −→𝜈 𝜏ˆ ∈ 𝜏/alloc(T) := Þ 𝜏ˆ∈Obj(T) alloc(T) (𝜏, 𝜏ˆ) Stateful Values. Recall that stateful values (§ 2.2) represent return values that live in the context of a heap. They are modelled using the monad P : WI → WI given using a coend P(A) (w) = ∫ w↣w ′∈w↓u A(w ′ ) Þ w 𝜎↣− w′∈w↓u A(w ′ ) ∼ w ↓ u is the comma category over world w ∈ Obj(W) and u : WI → W. The quotient /∼ ensures that only observable allocations are relevant which is what models garbage collection. In the setting of FGLS, we take A = X ⊙ H for some X ∈ W. We refer the reader to § 2.2 for some examples. Resultlets. Recall that collections of heaps with a common set of public locations are modelled using stencils that have location variables. We similarly generalise stateful values with location variables to describe collections of stateful values with a common heap footprint. We refer to these collections of stateful values as resultlets. Definition 4.11. For a X : W → Set and template 𝜏, a resultlet r over ⟨𝜏, X⟩ is a r ∈ ResX𝜏 := Þ 𝜏 𝜌 −→𝜈 𝜏 ′∈Obj(𝜏/alloc(T) ) X [𝜏 ′ ] × TH(𝜏 ′ ) The data of a resultlet are
0:19
• An allocation morphism which allocates concrete locations.
• An X-valued return value .
• A template heap , that defines locations that have access to both , .
When is a concrete world , a resultlet has exactly the same data as a stateful value in the original hiding monad. Thus resultlets generalise stateful values from concrete worlds to templates with variables. Specifically, we have a map for every world :
Accordingly, we lift the actions on morphisms of the monad P to resultlets. This lifted action is not itself functional, since it does not account for the quotienting built into P. Nevertheless, this is harmless: functionality is only required at concrete worlds, and it is recovered by the map q.
Definition 4.12 (Covariant action on morphisms in W). A , and induces defined as
It changes a resultlet over to one over .
Definition 4.13 (Covariant action on morphisms in TII). For a and a resultlet , we first lift to a morphism in TII by selecting the allocation data:
. We then consider the local independent general unifier which which
exists because is variable preserving. Define the covariant action as
Definition 4.14 (Contravariant action on morphisms in alloc(T)). Every allocation morphism in induces given by . We call this action hiding as it forgets some of the public locations.
We call a finite collection of resultlets as an evaluation.
Definition 4.15 (Evaluation). For a , and , an evaluation is an -indexed family of resultlets, .
In summary, resultlets play the role of compatible stateful values, and an evaluation is a finite family of resultlets, one for each stencil of a cover. The pair consisting of a cover and an evaluation can therefore be understood as a finite decision tree: the cover determines which case of the input heap we are in, and the evaluation specifies the corresponding output behaviour. Formally, we link covers and evaluations to local state computations using the notion of realisation.
Definition 4.16 (Realisation). A complete cover cov over and an X-valued evaluation ev over , realises , notation cov, ev , if for every ,
where morphism is given by completeness:
0:20
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
4.3 The Monad
We are now in a position to describe the finitary fragment of the FGLS monad.
Definition 4.17 (Finitary FGLS Monad).
A finitary is one that can be realised by a finite family of templates, a complete cover and evaluation. The existential given here is mere existence, so the actual cover and evaluation needed to realise a finitary is not observable, nor is it unique.
The following two theorems give the functional and monad structure of by lifting it through the actions on . One can easily show that monad is strong by a similar lifting of the strength for , and we therefore have a strong monad morphism given by the inclusion. Theorem 3 lastly shows that is indeed finitary.
Theorem 1 (Functor Structure). The action of on morphisms and applied to finitary computations preserve finitarity.
Proof Sketch. Consider a finitary , with , cov, ev.
is given at as . Then to show that is finitary take the same cover cov, and define a new evaluation at as .
is given at as . To show that is finitary, we first rebase cov using Definition 4.5 which gives a complete cover over . And define evaluation at as .
Theorem 2 (Monad Structure). The unit of gives a finitary computation and the join of applied to finitary computations yields a finitary one.
Proof Sketch. The unit is given at as . To show that is finitary, consider the identity cover . It is easy to see that it is complete. Define the evaluation at template as resultlet .
Multiplication involves a number of steps. From finitariness of , we have a complete cover cov over and -valued evaluation ev s.t. cov, ev . Unpacking this, the resultlet at every gives
• Morphism , finitary computation , and heap .
- Every further gives a , complete cover over and -valued evaluation over .
0:21
Firstly, we define its family of templates by unifying every with , which is given by the following pushout in . We then select only templates that are compatible with allocation ( with the allocation data): when the right-most square is a local independent general unifier.
selects the from every such compatible and morphism given by the is complete. This defines the cover since connected morphisms are closed under composition. Lastly, the evaluation is given at every as
Use the hiding algebras of ([15]) to prove realisation.
Theorem 3 (Finitarity). Monad is finitary.
Proof Sketch. We need to show that preserves filtered colimits. Let be a filtered colimit and we need to show the induced cocone morphism colimit is iso. We give the construction of the inverse. By finitarity of , we have that a finitary has a finite family of objects in , . By filteredness, we can take the upper bound of these objects, denote it by , with morphisms for every . We then extend every resultlet to . We can show that this map (i) is invariant under which cover, evaluation pair that realises , and (ii) is the inverse morphism from the colimiting cocone.
5 Finitary Semantics for FGLS
In this section we give semantics to from § 2.1 using the finitary FGLS monad. We interpret types as functors that carry a covariant structure. We show that generic effects read, write and alloc are finitary computations allowing us to interpret terms. Lastly, we show a correspondence between the semantics for given via the two monads.
5.1 Semantics of Types
Figure 5 gives the interpretation of types as covariant functors : given a , we can extend a to a . For the interpretation is standard using the bi-cartesian closed structure of and monad [23, 24]. For reference types , we use the representable functor . Thus a is an injection giving us a single location in . The covariant structure of says that location remains available for every extension of .
5.2 State Manipulating Generic Effects
Generic Effect Read. For every sort , monad supports generic effect which returns the contents of location :
0:22
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
Fig. 5. Interpretation of types in W.
is finitary since it only inspects a single location on the heap and full ground types have finite inhabitants. Formally we use the fact that sorts with full ground interpretation can be enumerated (see Definition 4.8). Denote its enumeration as . By yoneda we have , and let its complete cover be . The evaluation at every is resultlet .
Generic Effect Write. Morphism is given as
write_C lifts through monad as follows. Notice that is a morphism and let be an enumeration of as before. We first rebase cover (Definition 4.5) via , which induces a complete cover over . Define the evaluation at every as resultlet
Generic Effect Alloc. Recursive mutual allocation of locations is given by generic allocation alloc. For every world to be allocated, we have . The extension functor adds -many locations, and so at a world , we have -many values . Notice that is equivalent to a morphism in . Therefore, is given as
using the local independent coproduct and notice that can be equipped
with the data of (see [15]).
We show that is finitary by selecting the identity cover . For the resultlet, let be the template with locations and concrete ones. We have an allocation morphism in . Define the resultlet as .
5.3 Semantics of Terms
Typing judgments are interpreted as natural transformations in W:
Contexts are interpreted component-wise , and world in judgment is modelled using the representable functor : it defines only at worlds that have an injection , i.e., worlds bigger than .
0:23
Fig. 6. Interpretation of values in W
[\Gamma\vdash_{w}\mathbf{c a s e}M\{}\colon B]=\mathcal{T}_{\mathrm{f i n}}(\mathbf{?}_{[B]})\circ[M]Fig. 7. Interpretation of expressions in W
The interpretation of values (Figure 6 is mostly standard. It expects a location environment that associates location literals l with the current world, and a variable environment to interpret variables in context.
For the denotation of expressions (Figure 7), first denote the strength as , and the kleisli extension of a morphism as . Further, define the left-to-right double strength dstr as (where swap ):
Lastly, let be the unique morphism from the initial object, and let be the distribution of products over sums given by the bi-ccc structure.
Semantically, a value is an expression by postcomposing with unit . Constructs for applications, products and sums are interpreted in a standard way. For equality testing on references we use defined as . For reading, writing and allocation we use the generic effects given at § 5.2. For allocation, we first lift environment to and extend it to . We then apply with values where .
0:24
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
5.4 Metatheory
Let denote the interpretation of terms using the full monad , given identically to the one above. At full-ground types , the denotations are identical , whereas at higher types they differ since .
Recall from § 4.3 that is related with using a strong monad morphism . We can therefore establish a relationship between denotations of first-order terms given by the two monads [17].
Theorem 4. For every first-order term we have .
Adequacy from the semantics extends to using Theorem 4. Soundness of the semantics w.r.t. the operational semantics and compositionality is proven in the standard way by inducting over the derivations.
6 Related Work
Moggi [24] gave a unified categorical semantics for modelling various computational effects and specifically gave a possible worlds monad on a functor category for dynamic allocation of ground storage. Expanding on Moggi's work, Plotkin and Power [26] considered monads induced by suitable equations over the effectful operations, giving an equational account of computational effects. They further define a richer (ground) local state monad that supported garbage collection capabilities. Our work is based on the FGLS monad of Kammar et al. [15] that follows along this direction by giving a monad for full ground local state. Polzer and Goncharov [27] complement the semantics of [15] by developing a higher-order logic over the FGLS monad based on bi-hyperdoctorines.
Multiple relational models for local state exist in the literature that rely on auxiliary logical relations built on top of the semantics [5–7, 9–11]. These vary from utilising a continuation monad over nominal-cpos [7, 11], incorporating region-based effect typing in their reasoning [5, 6], and consider kripke logical relations over recursively defined set of worlds using metric spaces based semantics [10].
In any case, the relative simplicity of the underlying denotational semantics means that they fail to validate desired equivalences involving unobservable allocations. Instead it allows them to model complex features such as general references, recursive types and parametric polymorphism. They employ logical relations to refine their model allowing them to reason about properties such as observational equivalence. In contrast, the possible worlds semantics of [15, 26] builds garbage collection into the model, complicating the model but avoid requiring auxiliary logical relations.
Syntactic step-indexed logical relations built over the operational semantics have also been successful in modelling multiple non-trivial programming language constructs in conjunction such as recursive, abstract, polymorphic types, general references and control effects [2, 3, 9, 12]. By marrying the reasoning with separation logic [14, 34] they are able to prove deep properties of higher-order concurrent programs that make use of general references. We instead focus on denotational accounts of local state that abstract away from lower-level operational considerations.
An alternative class of models is based on game semantics, which differs from the aforementioned models as the semantics of heaps is implicit [1, 19, 25]. In this line of work, execution of a program is modelled as a dialogue between the player representing the program and the opponent being the environment. Game semantics is suitable for modelling full ground and general references and produces models that are fully abstract at higher-order types. Nevertheless, these models are fundamentally different from the possible worlds semantics we are concerned with.
7 Conclusion and Future Work
We extend the metatheory of the FGLS monad introduced in [15] by resolving an outstanding question on whether it is finitary. We show a negative result and therefore introduce a finitary
0:25
FGLS submonad. This submonad paves the way towards finitary equational axiomatisations of FGLS that are more amenable to reasoning.
There are several directions for future work. A useful property for a semantics is full abstraction at first order types [1, 16, 22, 33]. It states that for terms , observational equivalence implies denotational equality: , where , are first order, i.e., do not have any function types. Together with adequacy, full abstraction at first order identifies observational and denotational equality of first order terms. Such a property is used to show that the model is complete for compiler optimisations on imperative programs involving full ground references. This is typically the best-possible result, as models given by sets with structure and structure preserving functions are not typically fully abstract at higher order. We conjecture that the FGLS monad is fully abstract at first order, and that we can use techniques inspired by game semantics to prove that this is the case. This result would then transfer to the finitary submonad, and we can exploit its finitary nature to develop decision procedures to decide whether two terms are observationally equivalent.
We also aim to generalise the equations for ground local state [26, 31, 32] to the full-ground setting. This is a non-trivial task for two reasons: (i) one must identify an appropriate framework in which heap values can be treated as first-class entities, and (ii) one must account for the symmetries present within an allocated block of data. The goal is to obtain an equational axiomatisation giving rise to the finitary FGLS monad developed here.
Furthermore, we aim to increase the expressivity of the FGLS monad by reformulating it over W-indexed functors into cpos. This would allow us to support general recursion and would be a further step towards modelling higher-order store. As an additional benefit, such a domain-theoretic presentation of the FGLS monad may offer an alternative characterisation of the finitary submonad in terms of abstract domain constructions.
Finally, it would be worthwhile to investigate which programming-language constructs can express complete heap traversals without introducing a primitive operation that returns the size of the heap, such as heapSize from § 2.3. We expect, however, that such an operation would have no substantial impact on the metatheory: the FGLS monad would still fail to be fully abstract at higher-order types.
Acknowledgments
Ohad Kammar was funded by a Royal Society University Research Fellowship, Sam Lindley was supported by a UKRI Future Leaders Fellowship “Effect Handler Oriented Programming” (MR/T043830/1 and MR/Z000351/1), and Cristina Matache was partly supported by a Leverhulme Early Career Fellowship. We thank the Paul B. Levy for useful discussions and suggestions.
References
[1] Samson Abramsky, Kohei Honda, and Guy McCusker. 1998. A Fully Abstract Game Semantics for General References. In IEEE Symposium on Logic in Computer Science. IEEE Computer Society, Indiana, USA, 334–344. doi:10.1109/LICS.1998.705669
[2] Amal Ahmed, Derek Dreyer, and Andreas Rossberg. 2009. State-dependent representation independence. In POPL. ACM, Savannah, GA, USA, 340–353. doi:10.1145/1480881.1480925
[3] Amal J. Ahmed, Matthew Fluet, and Greg Morrisett. 2005. A step-indexed model of substructural state. In ICFP. ACM, Tallinn, Estonia, 78–91. doi:10.1145/1086365.1086376
[4] Andrej Bauer. 2018. What is algebraic about algebraic effects and handlers? CoRR abs/1807.05923 (2018). arXiv:1807.05923 http://arxiv.org/abs/1807.05923
[5] Nick Benton, Martin Hofmann, and Vivek Nigam. 2014. Abstract effects and proof-relevant logical relations. In POPL. ACM, San Diego, CA, USA, 619–632. doi:10.1145/2535838.2535869
[6] Nick Benton, Andrew Kennedy, Lennart Beringer, and Martin Hofmann. 2007. Relational semantics for effect-based program transformations with dynamic allocation. In PPDP. ACM, Wroclaw, Poland, 87–96. doi:10.1145/1273920.
0:26
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
1273932
[7] Nick Benton and Benjamin Leperchey. 2005. Relational Reasoning in a Nominal Semantics for Storage. In TLCA (Lecture Notes in Computer Science, Vol. 3461), Pawel Urzyczyn (Ed.). Springer, Nara, Japan, 86–101. doi:10.1007/11417170_8
[8] Clemens Berger, Paul-André Melliès, and Mark Weber. 2012. Monads with arities and their associated theories. Journal of Pure and Applied Algebra 216, 8 (2012), 2029–2048. Special Issue devoted to the International Conference in Category Theory ‘CT2010’. doi:10.1016/j.jpaa.2012.02.039
[9] Lars Birkedal, Bernhard Reus, Jan Schwinghammer, Kristian Støvring, Jacob Thamsborg, and Hongseok Yang. 2011. Step-indexed Kripke models over recursive worlds. ACM sigplan notices 46, 1 (2011), 119–132.
[10] Lars Birkedal, Kristian Støvring, and Jacob Thamsborg. 2010. Realisability semantics of parametric polymorphism, general references and recursive types. Math. Struct. Comput. Sci. 20, 4 (2010), 655–703. doi:10.1017/S0960129510000162
[11] Nina Bohr and Lars Birkedal. 2006. Relational Reasoning for Recursive Types and References. In APLAS (Lecture Notes in Computer Science, Vol. 4279), Naoki Kobayashi (Ed.). Springer, Sydney, Australia, 79–96. doi:10.1007/11924661_5
[12] Derek Dreyer, Georg Neis, and Lars Birkedal. 2012. The impact of higher-order state and control effects on local relational reasoning. J. Funct. Program. 22, 4-5 (2012), 477–528. doi:10.1017/S095679681200024X
[13] Martin Hyland and John Power. 2007. The Category Theoretic Understanding of Universal Algebra: Lawvere Theories and Monads. 172 (2007), 437–458. doi:10.1016/J.ENTCS.2007.02.019
[14] Ralf Jung, Robbert Krebbers, Jacques-Henri Jourdan, Ales Bizjak, Lars Birkedal, and Derek Dreyer. 2018. Iris from the ground up: A modular foundation for higher-order concurrent separation logic. J. Funct. Program. 28 (2018), e20. doi:10.1017/S0956796818000151
[15] Ohad Kammar, Paul Blain Levy, Sean K. Moss, and Sam Staton. 2017. A monad for full ground reference cells. In LICS. IEEE Computer Society, Reykjavik, Iceland, 1–12. doi:10.1109/LICS.2017.8005109
[16] Ohad Kammar, Jack Liell-Cock, Sam Lindley, Cristina Matache, and Sam Staton. 2026. An Equational Axiomatization of Dynamic Threads via Algebraic Effects: Presheaves on Finite Relations, Labelled Posets, and Parameterized Algebraic Theories. Proc. ACM Program. Lang. 10, POPL (2026), 1847–1875. doi:10.1145/3776706
[17] Shin-ya Katsumata. 2013. Relating computational effects by TT-lifting. Information and Computation 222 (2013), 228–246.
[18] Gregory M Kelly. 1982. Structures defined by finite limits in the enriched context, I. Cahiers de Topologie et Géométrie Différentielle 23, 1 (1982), 3–42.
[19] J. Laird. 2008. A game semantics of names and pointers. Annals of Pure and Applied Logic 151, 2 (2008), 151–169. doi:10.1016/j.apal.2007.10.006
[20] P. J. Landin. 1964. The Mechanical Evaluation of Expressions. Comput. J. 6, 4 (1964), 308–320. doi:10.1093/COMJNL/6.4.308
[21] Fred EJ Linton. 1966. Some aspects of equational categories. In Proceedings of the Conference on Categorical Algebra. Springer, Berlin, Heidelberg, 84–94.
[22] Robin Milner. 1977. Fully Abstract Models of Typed lambda-Calculi. Theor. Comput. Sci. 4, 1 (1977), 1–22. doi:10.1016/0304-3975(77)90053-6
[23] Eugenio Moggi. 1989. Computational Lambda-Calculus and Monads. In LICS. IEEE Computer Society, Pacific Grove, California, USA, 14–23. doi:10.1109/LICS.1989.39155
[24] Eugenio Moggi. 1990. An abstract view of programming languages. University of Edinburgh. Department of Computer Science, Edinburgh, UK.
[25] Andrzej S. Murawski and Nikos Tzevelekos. 2012. Algorithmic Games for Full Ground References. In ICALP (Lecture Notes in Computer Science, Vol. 7392). Springer, Warwick, UK, 312–324. doi:10.1007/978-3-642-31585-5_30
[26] Gordon D. Plotkin and John Power. 2002. Notions of Computation Determine Monads. In FOSSACS (Lecture Notes in Computer Science, Vol. 2303). Springer, Grenoble, France, 342–356. doi:10.1007/3-540-45931-6_24
[27] Miriam Polzer and Sergey Goncharov. 2020. Local local reasoning: A bi-hyperdoctrine for full ground store. In FoSSaCS. Springer, Springer International Publishing, Cham, 542–561.
[28] John Power. 1999. Enriched lawvere theories. Theory and Applications of Categories 6, 7 (1999), 83–93.
[29] Edmund Robinson. 2002. Variations on algebra: Monadicity and generalisations of equational therories. Formal Aspects of Computing 13, 3 (2002), 308–326.
[30] Alex Simpson. 2018. Category-theoretic structure for independence and conditional independence. Electronic Notes in Theoretical Computer Science 336 (2018), 281–297.
[31] Sam Staton. 2010. Completeness for Algebraic Theories of Local State. In FOSSACS (Lecture Notes in Computer Science, Vol. 6014), C.-H. Luke Ong (Ed.). Springer, Paphos, Cyprus, 48–63. doi:10.1007/978-3-642-12032-9_5
[32] Sam Staton. 2013. Instances of Computational Effects: An Algebraic Perspective. In LICS. IEEE Computer Society, New Orleans, LA, USA, 519. doi:10.1109/LICS.2013.58
[33] Thomas Streicher. 2006. Domain-theoretic foundations of functional programming. World Scientific, Toh Tuck Link, Singapore.
0:27
[34] Amin Timany, Robbert Krebbers, Derek Dreyer, and Lars Birkedal. 2024. A Logical Approach to Type Soundness. J. ACM 71, 6 (2024), 40:1–40:75. doi:10.1145/3676954
0:28
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
A Appendix
A.1 Full Specification of
(λ-calculus)
(Location Literals)
(Products)
(Sums)
(Values and Application)
(Products)
(Sums)
(References)
Fig. 8. Syntax of
Fig. 9. Typing rules of
0:29
Fig. 10. Reduction rules of in big-step
A.2 Non-Finitariness of FGLS Monad
Lemma A.1. Monad T does not preserve filtered colimits.
PROOF. Recall the local state function heapSize from § 2.3, and for simplicity, assume we have only one sort nat. It is straightforward to extend heapSize to any interpretation function defined over the full ground types of § 2.1.
heapSize takes a location : nat, traverses the heap starting from and returns the number of distinct locations it has found. Let be the constant functor in
where
0:30
Orpheas van Rooij, Ohad Kammar, Sam Lindley, and Cristina Matache
Notice that go is well-founded since S strictly reduces in size at every recursive call. It also satisfies the coherence condition of the End as it only traverses the reachable part of the heap w.r.t. public location l.
To show that heapSize is a counterexample to being finitary we need a filtered colimit that is not preserved by . Consider the (filtered) posetal category of natural numbers with the usual ordering, and let be the functor that maps each to its down-set, . does not preserve the (filtered) colimit because the mapping given by the appropriate inclusion
is not surjective: there is no n that defines heapSize
□