You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example of a function that requires a non-list invariant (i.e non-trivial structure for pre-condition).
type'a tree =
| Leaf
| Nodeof'a*'atree*'atreeletrec reducefbaset=match t with|Leaf -> base
|Node (vl, t1, t2) ->
let t1 = reduce f base t1 inlet t2 = reduce f base t2 in
f t1 vl t2
lethd_orlsvl=match ls with|[] -> vl
|hd :: _ -> hd
lettl_safels=match ls with|[] -> []|_ :: tl -> tl
letcount_and_copyt=let s =ref[]inlet f = (funt1vlt2 ->
let count =1+ t1 + t2 inlet t2 = hd_or !s Leafin
s := tl_safe !s;
let t1 = hd_or !s Leafin
s := tl_safe !s;
s := (Node (vl, t1, t2)) :: !s;
count
) inlet count = reduce f 0 t in
(count, List.hd !s)
The text was updated successfully, but these errors were encountered:
Example of a function that requires a non-list invariant (i.e non-trivial structure for pre-condition).
The text was updated successfully, but these errors were encountered: