2 (* Traversing a tree inorder, filling an array with the elements
3 (from Rustan Leino's tutorial on Dafny at VSTTE 2012)
5 Author: Jean-Christophe Filliatre (CNRS)
14 type tree = Null | Node tree elt tree
16 predicate contains (t: tree) (x: elt) = match t with
18 | Node l y r -> contains l x || x = y || contains r x
21 let rec fill (t: tree) (a: array elt) (start: int) : int
22 requires { 0 <= start <= length a }
23 ensures { start <= result <= length a }
24 ensures { forall i: int. 0 <= i < start -> a[i] = (old a)[i] }
25 ensures { forall i: int. start <= i < result -> contains t a[i] }
31 let res = fill l a start in
32 if res <> length a then begin