def array_run
import bendtorch-core@0.1.0.0/src/tensor/reduction.bend as Reductionimport Base
71# The fuel + 1 words of the array from slot `cursor`, whose read `pair` is
72# already made, added to `accumulator` left to right. Each step reads the
73# next word and hands it on as an argument: one tail call with no checked
74# read and no closure per word.
75def array_run(fuel: Nat, +cursor: Nat, accumulator: F32, pair: Array<F32> & F32) -> F32 & Array<F32>:
76 match fuel pair:
77 case 0n Tuple{array, word}:
78 (F32.add(accumulator, word), array)
79 case 1n+rest Tuple{array, word}:
80 array_run(rest, 1n+cursor, F32.add(accumulator, word), Array.get(F32, array, U32.from_nat(1n+cursor)))