2 (** {1 Polymorphic n-ary trees} *)
4 (** {2 Basic theory with polymorphic lists of children} *)
10 type forest 'a = list (tree 'a)
11 with tree 'a = Node 'a (forest 'a)
23 let rec function size_forest (f: forest 'a) : int
24 ensures { result >= 0 }
27 | Cons t f -> size_tree t + size_forest f
29 with function size_tree (t: tree 'a) : int
30 ensures { result > 0 }
32 | Node _ f -> 1 + size_forest f
45 | N 'a (forest 'a) (forest 'a)
49 (** {2 Forest size} *)
56 let rec function size_forest (f: forest 'a) : int
57 ensures { result >= 0 }
60 | N _ f1 f2 -> 1 + size_forest f1 + size_forest f2
65 (** {2 Membership in a forest} *)
71 predicate mem_forest (n: 'a) (f: forest 'a) = match f with
73 | N i f1 f2 -> i = n || mem_forest n f1 || mem_forest n f2