-
Notifications
You must be signed in to change notification settings - Fork 14
/
array-util.sml
executable file
·59 lines (47 loc) · 1.29 KB
/
array-util.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
structure ArrayUtil :> ARRAY_UTIL =
struct
fun foldriLazy f x arr =
let
val len = Array.length arr
fun loop i =
if i >= len then
x
else
f (i, Array.sub (arr, i), Susp.delay (fn () => loop (i+1)))
in
loop 0
end
fun foldrLazy f x arr =
let
val len = Array.length arr
fun loop i =
if i >= len then
x
else
f (Array.sub (arr, i), Susp.delay (fn () => loop (i+1)))
in
loop 0
end
fun foldliLazy f x arr =
let
val len = Array.length arr
fun loop i =
if i < 0 then
x
else
f (i, Array.sub (arr, i), Susp.delay (fn () => loop (i-1)))
in
loop (len-1)
end
fun foldlLazy f x arr =
let
val len = Array.length arr
fun loop i =
if i < 0 then
x
else
f (Array.sub (arr, i), Susp.delay (fn () => loop (i-1)))
in
loop (len-1)
end
end