123456789101112131415161718192021222324252627282930313233343536373839404142434445(*****************************************************************************)(* *)(* Copyright (C) 2026 Yves Ndiaye *)(* *)(* This Source Code Form is subject to the terms of the Mozilla Public *)(* License, v. 2.0. If a copy of the MPL was not distributed with this *)(* file, You can obtain one at https://mozilla.org/MPL/2.0/. *)(* *)(*****************************************************************************)(** Operations on ranges. *)(** type of range values. *)type'at=Valueof'a|Rangeof'aoption*'aoption(** [value v] is [Value v]. *)letvaluee=Valuee(** [range lhs rhs] is [Range lhs rhs]. *)letrangelhsrhs=Range(lhs,rhs)(** [to_string some range] is the string representation of [range] using [some].
*)letto_stringsome=function|Valuev->somev|Range(lhs,rhs)->letlhs=Option.fold~none:String.empty~somelhsinletrhs=Option.fold~none:String.empty~somerhsinPrintf.sprintf"%s..%s"lhsrhs(** [matches range v] tests whether [v] matches [ranges]. All extrema borns are
included. *)letmatchesrangev=matchrangewith|Range(None,None)->true|Range(Somet,None)->v>=t|Range(None,Somet)->v<=t|Range(Somelhs,Somerhs)->v>=lhs&&v<=rhs|Valueh->v=h