4 use export real.RealInfix
7 type or_integer_float = Integer int | Real real
10 (* sum integers in a list *)
11 function add_int (e: list or_integer_float) : int =
14 | Cons (Integer n) t -> n + add_int t
15 | Cons _ t -> add_int t
18 (* sum reals in a list *)
19 function add_real (e: list or_integer_float) : real =
22 | Cons (Real x) t -> x +. add_real t
23 | Cons _ t -> add_real t
32 let rec sum (l: list or_integer_float) : (si: int, sf: real) =
34 ensures { si = add_int l /\ sf = add_real l }
41 | Integer n -> n + a, b
49 Cons (Integer 5) (Cons (Real 3.3) (Cons (Integer 8)
50 (Cons (Real 1.4) (Cons (Integer 9) Nil))))
64 let sum (l: list or_integer_float) : (si: int, sf: real) =
65 ensures { si = add_int l /\ sf = add_real l }
71 invariant { !si + add_int !ll = add_int l /\
72 !sf +. add_real !ll = add_real l }
75 | Nil -> return !si, !sf
76 | Cons (Integer n) t ->
77 si := !si + n; ll := t
79 sf := !sf +. x; ll := t
88 Cons (Integer 5) (Cons (Real 3.3) (Cons (Integer 8)
89 (Cons (Real 1.4) (Cons (Integer 9) Nil))))