4 let create () : unit = ()
11 let test_Constant () =
12 for x in () with Constant do
23 mutable index: int; (* next index *)
25 invariant { 0 <= index <= Array.length a }
26 by { a = Array.make 0 (any 'a); index = 0 }
28 val create (a: array 'a) : t 'a
29 ensures { result.a = a }
30 ensures { result.index = 0 }
34 val next (t: t 'a) : (int, 'a)
36 raises { Done -> t.index = old t.index = Array.length t.a }
37 ensures { old t.index < Array.length t.a }
38 returns { i, x -> i = old t.index && t.index = i + 1 && x = t.a[i] }
42 = let a = Array.make 10 1 in
44 for _, x in a with A do
45 invariant { s = it.A.index < 5 }
46 variant { 10 - it.A.index }
59 mutable visited: list 'a;
60 mutable upcoming: list 'a;
62 invariant { initial = visited ++ upcoming }
63 by { initial = Nil; visited = Nil; upcoming = Nil }
65 val create (l: list 'a) : t 'a
66 ensures { result.initial = result.upcoming = l }
70 val next (t: t 'a) : 'a
72 raises { Done -> t.upcoming = old t.upcoming = Nil }
73 ensures { match old t.upcoming with
75 | Cons x a -> result = x && t.upcoming = a end }
79 let l = Cons 1 (Cons 2 (Cons 3 Nil)) in
82 variant { length it.L.upcoming }
83 invariant { s = 0 && it.L.upcoming = Cons 1 (Cons 2 (Cons 3 Nil))
84 || s = 1 && it.L.upcoming = Cons 2 (Cons 3 Nil)
85 || s = 3 && it.L.upcoming = Cons 3 Nil
86 || s = 6 && it.L.upcoming = Nil }