check.bend
bend-osdev-array@0.1.0.1 · 44 lines · 5 definitions
1import Base
2import bend-osdev-array@0.1.0.1/array.bend as A
3
4
5
6
7
8
9def show_list(xs: List<U32>) -> String:
10 match xs:
11 case Nil{}:
12 ""
13 case Con{h, t}:
14 U32.show(h) ++ " " ++ show_list(t)
15
16
17def sample() -> Array<U32>:
18 a = Array.new(U32, 3n, 0)
19 a = Array.set(U32, a, 1, 10)
20 a = Array.set(U32, a, 5, 50)
21 Array.set(U32, a, 14, 60)
22
23
24def reads.go(n: Nat, +i: U32, r: Array<U32> & U32) -> String:
25 match n:
26 case 0n:
27 (a, x) = r
28 U32.show(x)
29 case 1n+p:
30 (a, x) = r
31 U32.show(x) ++ " " ++ reads.go(p, U32.add(i, 1), Array.get(U32, a, U32.add(i, 1)))
32
33def reads(n: Nat, a: Array<U32>) -> String:
34 reads.go(n, 0, Array.get(U32, a, 0))
35
36def main() -> IO(Unit):
37 do IO<Unit>:
38 IO.print(reads(9n, sample()))
39 IO.print(show_list(Array.to_list(~U32, sample())))
40 IO.print(Nat.show(A.Arrays.index(3n, 14)) ++ " " ++ Nat.show(A.Arrays.slots(3n)))
41
42
43
44