Formal semantics for side effects

Blog » Formal semantics for side effects

Posted on

Got an idea for formal semantics for operations with side-effects like IO operations, random, etc. It's inspired by Haskell's use of Category Theory as a semantic device and by the Z specification language (the ISO Standard is downloadable; see the small print below the price list. An outdated but still useful manual is here.)

The idea in brief is that we model the world as a category W, whose objects are events and whose sole arrow is a precedence operator ( >- , \succ in LaTeX). What the events represent specifically is irrelevant; we only care about an event "input 'c'" as an abstract event. Think of this as the infinite list of events that contains all possible permutations of real world events.

To provide the semantics of the execution of a program P, we establish an isomorphism between it and W. The isomorphism maps "opaque" terms (e.g. IO terms, random values, etc.) to events. Ordering is preserved by some kind of rule mapping textual precedence in P to event precedence in W. In other words, to model a particular execution of P we incorporate a subset of W into the semantic domain. The static semantics of P are expressed only in the semantic domain, excluding W.

Now the meaning of the program is the text of P, its mapping to a semantic domain (the usual denotational mapping for e.g. '3'), plus the set of all possible isomorphisms between opaque terms and W. The actual exposition is a little more complicated than that, but this conveys the general idea.

This allows us to express program semantics, including dynamic semantics, in a rigorous, formal model that completely excludes any hint of dynamics, contingency, side-effects, etc. The notion of evaluation is also eliminated.

Like this entry?