|
| 1 | +// SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> |
| 3 | += KitchenSpeak — Type-Theoretic Commentary |
| 4 | +:toc: |
| 5 | +:toclevels: 3 |
| 6 | +:icons: font |
| 7 | + |
| 8 | +[NOTE] |
| 9 | +==== |
| 10 | +This is a *companion* to `SPEC.adoc`, not an edit of it. The class's |
| 11 | +specification is authoritative for the term. This document maps each of the |
| 12 | +class's seven types onto standard type-theoretic foundations, names the |
| 13 | +terminological overlaps with existing mathematical usage, and marks the |
| 14 | +load-bearing proof obligations the class will need to discharge. |
| 15 | +
|
| 16 | +It is written to support teaching — not to correct the spec. |
| 17 | +==== |
| 18 | + |
| 19 | +== How to read this document |
| 20 | + |
| 21 | +For each of the seven types, we give four things: |
| 22 | + |
| 23 | +. *What the class said* — the informal description from `SPEC.adoc`. |
| 24 | +. *Formal foundation* — the standard type-theoretic construct it lines up |
| 25 | + with. |
| 26 | +. *Proof obligation* — what the target proof assistant (Agda, in this |
| 27 | + curriculum) actually needs to discharge. |
| 28 | +. *Terminological note* — where the class's vocabulary overlaps with |
| 29 | + pre-existing mathematical usage, so nobody is ambushed later. |
| 30 | + |
| 31 | +A final section treats the three production-mandatory syntactic constructs |
| 32 | +(`max_duration`, `on_fail`, `proving`) as what they structurally are: |
| 33 | +well-founded recursion witnesses, total case-splits on failure, and named |
| 34 | +existential witnesses. |
| 35 | + |
| 36 | +== The seven types |
| 37 | + |
| 38 | +=== Tropical ( `~` ) |
| 39 | + |
| 40 | +*What the class said.* Handles range and gradients (temperature, power). |
| 41 | +Prevents "binary overheat." Carries a `slope` and a `threshold`. |
| 42 | + |
| 43 | +*Formal foundation.* A refinement type over a physical quantity with units, |
| 44 | +equipped with a rate-of-change bound. In mainstream terminology: *units of |
| 45 | +measure* (à la F#) plus a *bounded-derivative refinement*. The setpoint |
| 46 | +operator `~` is best read as "approach value `v` with slope at most `s`," |
| 47 | +not as a propositional equality. |
| 48 | + |
| 49 | +*Proof obligation.* Given a setpoint `~ v slope s`, the emitted control |
| 50 | +trajectory must remain inside a safe envelope: at no time `t` does the |
| 51 | +quantity exceed a forbidden threshold. In Agda, this is a refinement proof |
| 52 | +on a time-indexed stream, typically discharged by a termination-with-measure |
| 53 | +argument on a bounded integrator. |
| 54 | + |
| 55 | +*Terminological note.* "Tropical" already names a real field of mathematics: |
| 56 | +the *tropical semiring* (min, +) and *tropical geometry*. The class's usage |
| 57 | +is metaphorical — tropical climate, ramping temperature — and has nothing |
| 58 | +to do with min-plus algebra. Worth saying once in class so nobody gets |
| 59 | +ambushed when they meet the other tropical. |
| 60 | + |
| 61 | +=== Linear ( `<-` ) |
| 62 | + |
| 63 | +*What the class said.* Handles resource consumption. Prevents ingredient |
| 64 | +duplication or hallucination. Tracks state via "consumption arrows." |
| 65 | + |
| 66 | +*Formal foundation.* *Girard's linear logic*, specifically the multiplicative |
| 67 | +fragment. Each linear resource inhabits a type that must be used exactly |
| 68 | +once. Operationally: a linear variable is consumed on use. The state |
| 69 | +transitions `Egg[State:Raw] -> Egg[State:Cracked]` are a typestate |
| 70 | +refinement on top of linearity. |
| 71 | + |
| 72 | +*Proof obligation.* For every program point, the linear context contains |
| 73 | +exactly the resources not yet consumed. A resource used twice is a type |
| 74 | +error; a resource left unused at the end of `orchestrate` is a leak. Agda's |
| 75 | +standard way of expressing this is a linear monad or a quantitative type |
| 76 | +theory encoding. |
| 77 | + |
| 78 | +*Terminological note.* The class writes the formal domain as "Affordance." |
| 79 | +That is *Donald Norman's HCI term* for what an object invites the user to |
| 80 | +do, not linear logic's formal content. The poetic bridge — an egg *affords* |
| 81 | +being cracked — is lovely, but keep the linear-logic sense in mind for the |
| 82 | +proofs. |
| 83 | + |
| 84 | +=== Choreographic ( `sync` ) |
| 85 | + |
| 86 | +*What the class said.* Handles concurrency and sequencing. Orchestrates |
| 87 | +multiple Chef Actors (Oven, Hob, Robot) without deadlocks. |
| 88 | + |
| 89 | +*Formal foundation.* *Session types* / *choreographic programming* (Honda, |
| 90 | +Yoshida, Carbone; Montesi). A `sync(A, B)` block is a multiparty session |
| 91 | +barrier: the global choreography specifies what each actor does, and the |
| 92 | +local projections are what each hardware persona actually executes. The |
| 93 | +optional `proving @witness_id` clause names the *barrier-release witness*. |
| 94 | + |
| 95 | +*Proof obligation.* Deadlock-freedom and progress. In the session-typed |
| 96 | +setting: every actor's local projection is compatible with the global |
| 97 | +choreography, and the projection is well-typed. |
| 98 | + |
| 99 | +*Terminological note.* None significant. The class's "Process Calculus" |
| 100 | +entry in the type table is correct territory. |
| 101 | + |
| 102 | +=== Echo ( `@` ) |
| 103 | + |
| 104 | +*What the class said.* Handles sensor feedback — the witness. Acoustic, |
| 105 | +visual, thermal sensor streams that confirm the physical world matches the |
| 106 | +instruction. |
| 107 | + |
| 108 | +*Formal foundation.* A *postulated oracle* that inhabits a proposition |
| 109 | +about the physical world. `@acoustic_signature == "rolling_boil"` is not |
| 110 | +derivable inside the proof system; it is a hypothesis supplied by a sensor |
| 111 | +pipeline. Formally, each echo-type comes with a *soundness postulate* that |
| 112 | +says "if the classifier emits `rolling_boil`, the pot is in fact at a |
| 113 | +rolling boil." Agda represents this as a `postulate`, Coq as an `Axiom`. |
| 114 | + |
| 115 | +*Proof obligation.* The proof *assumes* the classifier is sound and |
| 116 | +discharges the surrounding control flow. The classifier itself is |
| 117 | +*unverified* — an honest teaching moment about the boundary between proven |
| 118 | +and postulated. Separate, higher-assurance work (out of scope for |
| 119 | +KitchenSpeak v1.0) would replace each echo-postulate with a verified |
| 120 | +classifier or an empirical soundness bound. |
| 121 | + |
| 122 | +*Terminological note.* The class's "Witness / Predicate" entry is right. |
| 123 | +Emphasise the *postulated* nature in class. |
| 124 | + |
| 125 | +=== Dyadic ( `<~>` ) |
| 126 | + |
| 127 | +*What the class said.* Handles explicit binding. Locks two resources into a |
| 128 | +single logical unit (e.g. Flour + Water become Dough). |
| 129 | + |
| 130 | +*Formal foundation.* *Tensor product* in a linear / monoidal type theory: |
| 131 | +`Flour ⊗ Water` is a new linear resource that the binding actor consumes to |
| 132 | +produce `Dough`. In linear-logic notation: |
| 133 | + |
| 134 | + Flour ⊗ Water ⊢ Baridi_Robot : Dough |
| 135 | + |
| 136 | +where the two inputs on the left are consumed and the single output on the |
| 137 | +right is emitted. Dyadic binding is therefore an ordinary rule in linear |
| 138 | +logic, not a new formalism. |
| 139 | + |
| 140 | +*Proof obligation.* The tensor's two factors are both consumed (linearity), |
| 141 | +and the Dough resource now carries the union of their relevant typestate |
| 142 | +metadata (provenance). |
| 143 | + |
| 144 | +*Terminological note.* The class writes the formal domain as "Binary |
| 145 | +Relation." In standard usage, a binary relation is a subset of A×B — a |
| 146 | +*predicate*, not a *constructor*. Tensor product is closer to a |
| 147 | +*constructor*: given `a : A` and `b : B`, it builds a new value `a ⊗ b : |
| 148 | +A ⊗ B`. The distinction is a clean teaching moment: relations observe, |
| 149 | +constructors build. |
| 150 | + |
| 151 | +=== Ceremonial ( `ceremony` ) |
| 152 | + |
| 153 | +*What the class said.* Handles social context and pacing. Overrides |
| 154 | +hardware aggression based on occasion. Declared at the `orchestrate` block |
| 155 | +level. |
| 156 | + |
| 157 | +*Formal foundation.* An *ambient effect context* — most naturally encoded |
| 158 | +as a *reader monad* over the choreography, or as a *row of effect labels* |
| 159 | +in an algebraic-effects system. A ceremony *does not* change the linear |
| 160 | +resource count; it changes the *pace*, *alert level*, and *priority* with |
| 161 | +which the underlying choreography executes. |
| 162 | + |
| 163 | +*Proof obligation.* Ceremonies must be *separated* from linearity: they are |
| 164 | +permitted to tighten termination bounds and re-prioritise, but not to |
| 165 | +duplicate or discard linear resources. In effect-system terms, ceremony |
| 166 | +effects commute with linear-resource effects. |
| 167 | + |
| 168 | +*Terminological note.* "Contextual Logic" in the class's table is a fair |
| 169 | +informal gloss on reader / ambient-effect. |
| 170 | + |
| 171 | +=== Primitive |
| 172 | + |
| 173 | +*What the class said.* Raw SI units that talk to the hardware APIs. Mass |
| 174 | +(g), Temp (°C), Torque (Nm), Viscosity (Pa·s), Time (s). |
| 175 | + |
| 176 | +*Formal foundation.* *Units of measure* as in F# / Fortress / Frink — a |
| 177 | +phantom type per physical dimension, with multiplicative combinators. An |
| 178 | +expression of type `°C` cannot be compared for equality with an expression |
| 179 | +of type `s`. |
| 180 | + |
| 181 | +*Proof obligation.* All arithmetic on primitives preserves dimension. The |
| 182 | +Agda encoding is straightforward with indexed types; the subtlety is |
| 183 | +choosing a numeric carrier — rationals (with units) are usually enough and |
| 184 | +avoid the constructive-reals rabbit hole. |
| 185 | + |
| 186 | +*Terminological note.* "Primitive type" in everyday PL usage means `int`, |
| 187 | +`bool`, etc. Here it means something closer to "dimension-indexed physical |
| 188 | +quantity." Not wrong — worth naming. |
| 189 | + |
| 190 | +== The three production-mandatory constructs |
| 191 | + |
| 192 | +=== `max_duration` — termination witness |
| 193 | + |
| 194 | +Every `step` carries a `max_duration`. Structurally this is a *well-founded |
| 195 | +measure* on the implicit `until`-loop: the controller cannot run forever, |
| 196 | +because wall-clock time is a decreasing measure under a fixed bound. In |
| 197 | +Agda, this is the standard argument that makes `until` total. |
| 198 | + |
| 199 | +=== `on_fail { ABORT | RECOVER | WARM }` — total failure handler |
| 200 | + |
| 201 | +Every `step` specifies an `on_fail` behaviour. Structurally this is a |
| 202 | +*total case-split* on the failure branch: no step can get *stuck*, because |
| 203 | +every failure branch is inhabited by a named recovery mode. This makes the |
| 204 | +`sync_block` a total function into `{success} ⊎ {aborted, recovered, |
| 205 | +warmed}`. |
| 206 | + |
| 207 | +=== `proving @witness_id` — named existential witness |
| 208 | + |
| 209 | +The optional `proving` clause on a `sync_block` names the echo-postulate |
| 210 | +that certifies block completion. Structurally this is an *existential |
| 211 | +witness binder*: the block is total iff there exists a sensor event |
| 212 | +satisfying `@witness_id` within the block's `max_duration`. The postulate |
| 213 | +supplies the witness; the grammar makes its name explicit. |
| 214 | + |
| 215 | +== Why each type earns its keep in the curriculum |
| 216 | + |
| 217 | +A single sentence per type, for use in class: |
| 218 | + |
| 219 | +* *Tropical.* You can feel the difference between a refinement type and a |
| 220 | + raw numeric when you watch a chocolate tempering curve go wrong. |
| 221 | +* *Linear.* You cannot uncrack an egg. |
| 222 | +* *Choreographic.* The oven and the hob have to coordinate or the eggs |
| 223 | + scramble before the bacon crisps. |
| 224 | +* *Echo.* The proof that cooking is happening is that the pot is making |
| 225 | + the right noise. |
| 226 | +* *Dyadic.* Once flour and water have met, neither exists any more; dough |
| 227 | + does. |
| 228 | +* *Ceremonial.* Sunday lunch is paced differently from combat rations, and |
| 229 | + both are valid modes of the same choreography. |
| 230 | +* *Primitive.* 180 is not a temperature until you know what unit it's in. |
| 231 | + |
| 232 | +== Deliberately out of scope for v1.0 |
| 233 | + |
| 234 | +* A formal lexer specification (`actors`, `action`, `params`, `metric`, |
| 235 | + `comparison`, `value`, `time`, `error_handle` are placeholder |
| 236 | + nonterminals). |
| 237 | +* A verified classifier story for echo-types. v1.0 treats every `@witness` |
| 238 | + as postulated. |
| 239 | +* Nested `sync_block` / `bind_step` inside a `sync_block`. |
| 240 | +* A committed choice between Agda and Coq as the proof target. `SPEC.adoc` |
| 241 | + §4 names both ("Cook (Gallina)") but §6 uses Agda-specific terminology |
| 242 | + ("Yellow unproven goals"). This document uses Agda throughout for |
| 243 | + pedagogical tractability; the decision can be revisited. |
| 244 | +* A committed wire protocol. `SPEC.adoc` §5 names HomeConnect, SmartThings, |
| 245 | + and Tuya; Matter and MQTT are candidates for a later HAL revision. |
| 246 | + |
| 247 | +== Recommended reading for the class |
| 248 | + |
| 249 | +* Philip Wadler, _Linear Types can Change the World_ (1990) — the |
| 250 | + original motivation for linear logic in programming. |
| 251 | +* Kohei Honda, Nobuko Yoshida, Marco Carbone, _Multiparty Asynchronous |
| 252 | + Session Types_ (POPL 2008) — the choreographic type-theory baseline. |
| 253 | +* Conor McBride, _I Got Plenty o' Nuttin'_ — quantitative type theory, a |
| 254 | + modern treatment of linearity that generalises cleanly. |
| 255 | +* Andrej Bauer, _What is algebraic about algebraic effects and handlers?_ |
| 256 | + — effect systems without category theory prerequisites, for the |
| 257 | + ceremonial chapter. |
0 commit comments