123456789101112131415161718192021222324252627282930313233343536373839404142434445openCore_kerneltypet=stringlist[@@derivingsexp]letcompare=List.compareString.compareletrecnormalize=function|"."::t|""::t->normalizet|h::".."::t->lett=normalizetinifnot(String.equalh"..")thentelse".."::".."::t|h::t->h::normalizet|[]->[]letcommon_prefixpq=letrecauxrespq=matchp,qwith|h_p::t_p,h_q::t_qwhenPoly.(h_p=h_q)->aux(h_p::res)t_pt_q|_->List.revres,p,qinaux[]pqletof_stringx=matchString.split~on:'/'xwith|""::t->"/"::t|xs->xsletmake_relative?from:(q=Sys.getcwd())p=ifFilename.is_relativeqtheninvalid_argf"make_rel_path: base %s should be absolute"q()elseifFilename.is_relativepthenof_stringpelseletp=normalize(of_stringp)andq=normalize(of_stringq)inlet_,p_suffix,q_suffix=common_prefixpqinList.mapq_suffix~f:(const"..")@p_suffixletrecto_string=function|[]->"."|""::t->Filename.concat"."(to_stringt)|"/"::t->"/"^(to_stringt)|p->List.reduce_exnp~f:Filename.concat