(* Now we serialize the tree itself by first serializing the shape, and then a
     preorder traversal of the elements. *)
  Definition tree_serialize (t : tree A) : IOStreamWriter.t :=
    IOStreamWriter.append (fun _ => serialize_tree_shape t)
                  (fun _ => serialize_tree_elements t).

(* Specifications: *)
Lemma tree_serialize_deserialize_id : serialize_deserialize_id_spec tree_serialize tree_deserialize.