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. *)letinit=function[]->None|h::tl->Some(List_zip([],h,tl))letrecforward?(step=1)f_l=matchstep,f_lwith|n,_whenn=0->Somef_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->None|_,List_zip(h::c,f,tl)->forward~step:(step+1)(List_zip(c,h,f::tl))|_,List_zip([],_,_)->Noneletbackward=function|List_zip(h::tl,f,r)->Some(List_zip(tl,h,f::r))|List_zip([],_,_)->Noneletrecfoldfacc=function|List_zip((_,_,_)asfocus)aslst->letf_val=faccfocusinmatch(forwardlst)with|None->f_val|Somefl->foldff_valflletrecfold_forward?(include_focus=true)facc=function|List_zip(_,focus,_)aslst->letf_val=ifinclude_focusthenfaccfocuselseaccinmatch(forwardlst)with|None->f_val|Somefl->fold_forward~include_focus:trueff_valflletfocus(List_zip(_,a,_))=aletzip(List_zip(c,a,l))=List.fold_left(funaccelt->elt::acc)(a::l)cend