12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2017-2019 The MOPSA Project. *)(* *)(* This program is free software: you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License as published *)(* by the Free Software Foundation, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(**
Lift comparison to composed data-structure (pairs, lists, etc.).
*)(**
[compose cl] applies a list of comparison functions [cl] in sequence
and stops when encountering the first non-zero result.
*)letreccompose=function|[]->0|cmp::tl->letr=cmp()inifr<>0thenrelsecomposetl(** [list p] lifts the 'a compare function [p] to 'a list *)letlistp=funll'->ifl==l'then0elseletrecauxab=matcha,bwith|t::r,t'::r'->letx=ptt'inifx=0thenauxrr'elsex|[],t'::r'->-1|[],[]->0|t::r,[]->1inauxll'(** [pair p] lifts the 'a compare function [p], 'b compare
function [q] to 'a * 'b *)letpairpq=fun(a,b)(c,d)->ifa==c&&b==dthen0elseletx=pacinifx=0thenqbdelsex(** [triple p] lifts the 'a compare function [p], 'b compare
function [q], 'c compare function [r] to 'a * 'b * 'c *)lettriplepqr=fun(a,b,c)(d,e,f)->ifa==d&&b==e&&c==fthen0elseletx=padinifx=0thenlety=qbeinify=0thenrcfelseyelsexletquadruplepqrs=fun(a,b,c,d)(e,f,g,h)->ifa==e&&b==f&&c==g&&d==hthen0elseletx=paeinifx=0thenlety=qbfinify=0thenletz=rcginifz=0thensdhelsezelseyelsex(** [option p] lifts [p: 'a -> 'a -> int] to ['a option -> 'a option -> int] *)letoptionpqr=ifq==rthen0elsematchq,rwith|Somex,Somey->pxy|_->Stdlib.compareqr