Folding Through Layers of Glass
When you deposit thin films, you’re building optical properties layer by layer. A magnesium fluoride layer adds 140nm of phase shift. Then titanium dioxide adds another 68nm. Then silicon dioxide. Each layer transforms the electromagnetic field propagating through it, and the final behaviour emerges from the accumulated effect of every interface.
This is a fold operation. You have a sequence of layers, an initial state (incident light), and a function that says “given the current optical state and this layer’s properties, what’s the new state?” Fold walks through the layers, threading the accumulated result forward.
In Clojure, this is reduce:
(def layers [{:material "MgF2" :thickness 140}
{:material "TiO2" :thickness 68}
{:material "SiO2" :thickness 95}])
(defn add-layer [optical-thickness layer]
(+ optical-thickness (* (:thickness layer) 1.38)))
(reduce add-layer 0 layers)
;; => 418.14 (total optical thickness in nm)
Ada makes the accumulation explicit:
with Ada.Text_IO; use Ada.Text_IO;
procedure Fold_Coating is
type Layer is record
Thickness : Float;
Index : Float;
end record;
Layers : array(1..3) of Layer := ((140.0, 1.38), (68.0, 2.49), (95.0, 1.46));
Optical_Path : Float := 0.0;
begin
for L of Layers loop
Optical_Path := Optical_Path + L.Thickness * L.Index;
end loop;
Put_Line(Float'Image(Optical_Path));
end Fold_Coating;
The pattern is ancient—APL had reduction in the 1960s, LISP had recursive accumulation even earlier—but it formalized in the 1970s with Bird and Meertens’s work on catamorphisms. The name comes from Greek: “downward shape,” collapsing a structure into a single value.
In thin-film work, you’re literally folding optical path lengths. In compilers, you fold syntax trees into optimized code. Same principle: a sequence of transformations accumulated into one result. The coating chamber and the function pipeline run the same algorithm, just at different scales.