-
Notifications
You must be signed in to change notification settings - Fork 6
/
fold-evolve.timl
41 lines (37 loc) · 989 Bytes
/
fold-evolve.timl
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
structure FoldEvolve = struct
open List
val ['a 'b] foldl =
fn {m : Nat} (f : 'a * 'b -- $m --> 'b) =>
let
fun foldl {n : Nat} (y : 'b, xs : list 'a {n}) return 'b using $(m + 2) * $n =
case xs of
Nil => y
| Cons (x, xs) => foldl (f (x, y), xs)
in
foldl
end
absidx h : BigO (fn m n => $m * $n) with
val ['a 'b] foldl =
fn {m : Nat} (f : 'a * 'b -- $m --> 'b) =>
let
fun foldl {n : Nat} (y : 'b, xs : list 'a {n}) return 'b using h m n =
case xs of
Nil => y
| Cons (x, xs) => foldl (f (x, y), xs)
in
foldl
end
end
absidx h : BigO (fn m n => $m * $n) with
val ['a 'b] foldl =
fn {m : Nat} (f : 'a * 'b -- $m --> 'b) =>
let
fun foldl {n : Nat} y (xs : list 'a {n}) return 'b using h m n =
case xs of
Nil => y
| Cons (x, xs) => foldl (f (x, y)) xs
in
foldl
end
end
end