let cmp a b =
let rec loop al bl =
match al, bl with
| [], [] -> 0
| [], _ -> -1
| _, [] -> 1
| x :: xl', y :: yl' ->
let res = cmp1 (destruct x) (destruct y) in
if res = 0 then loop xl' yl' else res
in
loop (to_list a) (to_list b)