1234567891011121314151617181920212223242526272829303132open!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.id(* 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));;