Skip to content

Writing is a relation O writes R — operation O writes to resource R — asserting that O modifies R in place: R exists before O and after O, but its state has changed. The defining structure: writing is destructive modification — the resource's identity persists (it is still R) but its content changes. Writing is not consumption (the resource persists after writing) and not production (the resource existed before writing). Writing corresponds to exclusive write access in separation logic (full ownership that changes the pointed-to value), to transitions that modify a Petri net place's token count, and to the write effect in effect type systems.
Table of contents

Writes

Formal definition

Writing is a relation O writes RO \text{ writes } R:

(O:Operation,  R:ResourceType)(O : \mathrm{Operation},\; R : \mathrm{ResourceType})

holding when OO modifies an instance r:Rr : R in place — rr exists before OO and after OO, but its value has changed from some pre-state r0r_0 to a post-state r1=O(r0)r_1 = O(r_0).

Two invariants. O writes RO \text{ writes } R iff:

  1. Persistence with change: rr exists both before and after OO — writing is not destruction (which would remove rr) and not creation (which would bring rr into existence from nothing). The resource’s identity persists; its content changes.

  2. Exclusive access: OO requires exclusive control of rr during execution — no other concurrent operation may read or write rr during OO’s write. This is the separation condition: a write to rr requires full ownership of rr, not merely a fractional read share.

Separation logic: exclusive write

Peter O’Hearn, John Reynolds, Hongseok Yang (Local Reasoning about Programs that Alter Data Structures, 2001): in separation logic, writing to location xx requires full ownership xvx \mapsto v (the heap points-to assertion with no sharing):

{xv}  [x]:=w  {xw}\{x \mapsto v\}\; [x] := w\; \{x \mapsto w\}

After the write, xx points to ww instead of vv. The full-ownership requirement (xx \mapsto -, not xqx \xmapsto{q} - for fractional qq) is the formal content of exclusive write access: no other holder of a fractional share can permit concurrent modification.

The frame rule ensures locality: writing to xx does not affect any yxy \neq x in the frame RR:

{P}  [x]:=w  {Q}{PR}  [x]:=w  {QR} when xfv(R)\frac{\{P\}\; [x] := w\; \{Q\}}{\{P * R\}\; [x] := w\; \{Q * R\}} \text{ when } x \notin \mathrm{fv}(R)

Effect types: write effects

Lucassen and Gifford (Polymorphic Effect Systems, 1988): an operation type A{writes(r)}BA \xrightarrow{\{\mathrm{writes}(r)\}} B writes to region rr. Operations with write effects are not idempotent — calling twice from the same initial state may produce different results (if the first write changed the state the second call reads).

Talpin and Jouvelot (Polymorphic Type, Region and Effect Inference, JFP 2(3), 1992) give the explicit write typing rule. For a reference e1:refr(τ)e_1 : \mathrm{ref}^r(\tau) and new value e2:τe_2 : \tau:

Γe1:refr(τ)/ε1Γe2:τ/ε2Γe1:=e2:unit/ε1ε2{writes(r)}\frac{\Gamma \vdash e_1 : \mathrm{ref}^r(\tau) / \varepsilon_1 \qquad \Gamma \vdash e_2 : \tau / \varepsilon_2}{\Gamma \vdash e_1 := e_2 : \mathbf{unit} / \varepsilon_1 \cup \varepsilon_2 \cup \{\mathrm{writes}(r)\}}

The effect writes(r)\mathrm{writes}(r) accumulates in the caller’s effect set. Effect sets propagate upward: if ff calls gg and gg writes to rr, then ff’s type records writes(r)\mathrm{writes}(r) unless rr is locally allocated and not observable from outside ff.

Linear logic formulation: writing is AAA \multimap A' — the old resource AA is consumed and the new resource AA' (with updated content) is produced. This captures the destructive nature of writing precisely: the old value ceases to exist; the new value is a fresh linear resource. The separation logic mutation rule {xv} [x]:=w {xw}\{x \mapsto v\}\ [x] := w\ \{x \mapsto w\} is the heap-model realization of this: the old xvx \mapsto v resource is consumed and xwx \mapsto w is produced.

The effect lattice orders effects: reads(r)writes(r)\mathrm{reads}(r) \leq \mathrm{writes}(r) — writing implies reading (one must read before modifying). A function with only write effects still implicitly reads; effect type systems typically treat writes as subsuming reads.

Open questions

  • Whether writing (exclusive modification) is the categorical dual of reading (shared observation) in some category of resource interactions — whether the categories of “operations with read effects” and “operations with write effects” are dual categories in a formal sense.
  • Whether writes in the relational history correspond to updating the transfer nucleus — whether writing to a resource at history tt is the event that moves the resource from HtHtH_t \setminus H^*_t into Fix(Δt)\mathrm{Fix}(\Delta_{t'}) at some later history t>tt' > t.

Relations

Ast
Date created
Date modified
Defines
Writes
Operation
Relational universe morphism
Output
Relational universe morphism
Related
Reads, takes, consumes, produces, separation logic, effect type, state transition
Resource type
Relational universe