1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495(* This file is free software, part of containers. See file "license" for more details. *)(** {1 Comparisons} *)type'at='a->'a->int(** Comparison (total ordering) between two elements, that returns an int *)letpoly=Stdlib.compareletcompare=Stdlib.compareletoppfxy=-fxyletequivij=ifi<0thenj<0elseifi>0thenj>0elsej=0letint(x:int)y=Stdlib.comparexyletstring(x:string)y=Stdlib.comparexyletbool(x:bool)y=Stdlib.comparexyletfloat(x:float)y=Stdlib.comparexy(** {2 Lexicographic Combination} *)let(<?>)c(ord,x,y)=ifc=0thenordxyelsecletoptionco1o2=matcho1,o2with|None,None->0|None,Some_->-1|Some_,None->1|Somex1,Somex2->cx1x2letpairo_xo_y(x1,y1)(x2,y2)=letc=o_xx1x2inifc=0theno_yy1y2elseclettripleo_xo_yo_z(x1,y1,z1)(x2,y2,z2)=letc=o_xx1x2inifc=0then(letc'=o_yy1y2inifc'=0theno_zz1z2elsec')elsecletreclistordl1l2=matchl1,l2with|[],[]->0|[],_->-1|_,[]->1|x1::l1',x2::l2'->letc=ordx1x2inifc=0thenlistordl1'l2'elsecletarrayorda1a2=letrecauxi=ifi=Array.lengtha1thenifArray.lengtha1=Array.lengtha2then0else-1elseifi=Array.lengtha2then1else(letc=orda1.(i)a2.(i)inifc=0thenaux(i+1)elsec)inaux0letmapfordab=ord(fa)(fb)let(>|=)xf=mapfxmoduleInfix=structlet(>|=)=(>|=)let(<?>)=(<?>)end