1 import Base 2 import ./owner_product.bend as Product 3 # Only canonical product exchanges create these inverses. No body-provided inverse. 4 def replaced(~State:Type,~P:Type,~Rest:Type,~lens:Product.Lens,replacement:P,taken:Rest & P) -> State & P: 5 match taken: 6 case (rest,old):(Product.put_field(~State,~P,~Rest,lens)(rest,replacement),old) 7 def exchange(~State:Type,~P:Type,~Rest:Type,~lens:Product.Lens,state:State,replacement:P) -> State & P: 8 replaced(~State,~P,~Rest,~lens,replacement,Product.get_field(~State,~P,~Rest,lens)(state)) 9 def appended(~Recovery:Type,~P:Type,~Rest:Type,~lens:Product.Lens,Rest>,value:P,taken:Rest & List

) -> Recovery: 10 match taken: 11 case (rest,values):Product.put_field(~Recovery,~List

,~Rest,lens)(rest,value <> values) 12 def append(~Recovery:Type,~P:Type,~Rest:Type,~lens:Product.Lens,Rest>,recovery:Recovery,value:P) -> Recovery: 13 appended(~Recovery,~P,~Rest,~lens,value,Product.get_field(~Recovery,~List

,~Rest,lens)(recovery))