def OptState.join
import bendtorch@1.3.0.0/main.bend as Bendtorchimport Base
89# Pair the buffers present on both sides. Internal callers split one state, then step both children with the same
90# optimizer, so the variants agree. No buffer is ever allocated to fill an absent side.
91def OptState.join(-A: Type, -B: Type, a: OptState<A>, b: OptState<B>) -> OptState<Two<A, B>>:
92 match a b:
93 case OneMom{x} OneMom{y}: OneMom{Two{x, y}}
94 case TwoMom{x, u} TwoMom{y, v}: TwoMom{Two{x, y}, Two{u, v}}
95 case Packed{x} Packed{y}: Packed{PNode{x, y}}
96 case _ _: NoMom{}