def adc
import bend-lawful-stdlib@0.1.0.0/src/float/bin.bend as Binimport Base
77# a + b + carry, one bit at a time: bits 0+0 pass the carry through and
78# carry nothing, 0+1 flip it and carry it, 1+1 pass it and carry one
79def adc(a: Bin, b: Bin, +c: Bool) -> Bin:
80 match a b:
81 case BZ{} b:
82 adc.one(b, c)
83 case a BZ{}:
84 adc.one(a, c)
85 case B0{x} B0{y}:
86 cons(c, adc(x, y, False{}))
87 case B0{x} B1{y}:
88 cons(Bool.not(c), adc(x, y, c))
89 case B1{x} B0{y}:
90 cons(Bool.not(c), adc(x, y, c))
91 case B1{x} B1{y}:
92 cons(c, adc(x, y, True{}))