Fixpoint serialize_tree_elements (t : tree A) : IOStreamWriter.t :=
    let fix serialize_tree_elements_list (l : list (tree A)) : IOStreamWriter.t :=
        match l with
        | [] => IOStreamWriter.empty
        | t :: l' => IOStreamWriter.append (fun _ => serialize_tree_elements t)
                                   (fun _ => serialize_tree_elements_list l')
        end
    in match t with
       | atom a => serialize a
       | node l => serialize_tree_elements_list l
       end.Definition serialize_tree_elements_list :=
    fix serialize_tree_elements_list (l : list (tree A)) : IOStreamWriter.t :=
      match l with
      | [] => IOStreamWriter.empty
      | t :: l' => IOStreamWriter.append (fun _ => serialize_tree_elements t)
                                 (fun _ => serialize_tree_elements_list l')
      end.

(* Specifications: *)
Lemma serialize_deserialize_tree_elements_id : forall t bytes, ByteListReader.unwrap (deserialize_tree_elements (shape t)) (IOStreamWriter.unwrap (serialize_tree_elements t) ++ bytes) = Some (t, bytes).