def ex.go
import bend-parallel@0.1.0.0/scan.bend as Scanimport Base
51# r holds the array and the entry x read at j: a[j] becomes s, the sum
52# before it, and so on for the n entries after it. Returns the array and
53# the running sum past the last entry.
54def ex.go(+n: Nat, +j: U32, +s: U32, r: Array<U32> & U32) -> Array<U32> & U32:
55 match n:
56 case 0n:
57 (a, +x) = r
58 (a[j] <- s, (s + x : U32))
59 case 1n+p:
60 (a, +x) = r
61 +q = (j + 1 : U32)
62 ex.go(p, q, (s + x : U32), (a[j] <- s)[q])