123456789101112131415161718192021222324252627282930313233343536373839404142434445moduleFocused_list=structtype'at=|List_zipof('alist*'a*'alist)(** This type aims to implement a zipper for lists. The context is
the first parameter. It represents the list of the elements {e
in reverse order} that has been traversed to reach the focused
element (the second parameter). The last element is the
remaining elements of the list. *)exceptionEmpty_listexceptionEnd_of_listletinit=function[]->raiseEmpty_list|h::tl->List_zip([],h,tl)letrecforward?(step=1)f_l=matchstep,f_lwith|n,_whenn=0->f_l|n,List_zip(c,f,h::tl)whenn>0->forward~step:(step-1)(List_zip(f::c,h,tl))|n,List_zip(_,_,[])whenn>0->raiseEnd_of_list|_,List_zip(h::c,f,tl)->forward~step:(step+1)(List_zip(c,h,f::tl))|_,List_zip([],_,_)->raiseEnd_of_listletbackward=function|List_zip(h::tl,f,r)->List_zip(tl,h,f::r)|List_zip([],_,_)->raiseEnd_of_listletrecfoldfacc=function|List_zip((_,_,[])asfocus)->faccfocus|List_zip((_,_,_)asfocus)aslst->foldf(faccfocus)(forwardlst)letrecfold_forward?(include_focus=true)facc=function|List_zip(_,focus,[])->ifinclude_focusthenfaccfocuselseacc|List_zip(_,focus,_)aslst->ifinclude_focusthenfold_forward~include_focusf(faccfocus)(forwardlst)elsefold_forward~include_focus:truefacc(forwardlst)letfocus(List_zip(_,a,_))=aletzip(List_zip(c,a,l))=List.fold_left(funaccelt->elt::acc)(a::l)cend