123456789101112131415161718192021222324252627282930313233open!Baseopen!Importtype'at=|[]:unitt|(::):'a*'bt->('a*'b)tlethd(hd::_)=hdlettl(_::tl)=tlletrectail_recursive_with_tuple:typear.at->f:(a->r)->r=funt~f->matchtwith|[]->f()|hd::tl->tail_recursive_with_tupletl~f:(funtl->f(hd,tl));;letto_tuplet=tail_recursive_with_tuplet~f:Fn.idlethash_fold_thash_fold_tuplehash_statet=hash_fold_tuplehash_state(to_tuplet)(* renders like a list *)letsexp_of_tsexp_of_tuple=letrecloopacc=function|Sexp.List[]->Sexp.List(List.revacc)|Sexp.List[sexp;sexps]->loop(sexp::acc)sexps|(Sexp.Atom_|Sexp.List[_]|Sexp.List(_::_::_))assexp->raise_s[%message"Bug in Index.sexp_of_t: unexpected nested sexp for nested tuple"(sexp:Sexp.t)]infunt->loop[](sexp_of_tuple(to_tuplet));;