diff --git a/_oasis b/_oasis index 354e71f8..38f5e31b 100644 --- a/_oasis +++ b/_oasis @@ -8,7 +8,7 @@ LicenseFile: LICENSE Plugins: META (0.3), DevFiles (0.3) OCamlVersion: >= 4.00.1 BuildTools: ocamlbuild -AlphaFeatures: ocamlbuild_more_args, compiled_setup_ml +AlphaFeatures: compiled_setup_ml Synopsis: A modular standard library focused on data structures. Description: @@ -49,7 +49,7 @@ Library "containers" CCKList, CCInt, CCBool, CCArray, CCOrd, CCIO, CCRandom, CCKTree, CCTrie, CCString, CCHashtbl, CCFlatHashtbl, CCSexp, CCMap - BuildDepends: cppo + XMETARequires: cppo FindlibName: containers Library "containers_string" diff --git a/core/CCFun.ml b/core/CCFun.cppo.ml similarity index 91% rename from core/CCFun.ml rename to core/CCFun.cppo.ml index 55f1a337..49e2fada 100644 --- a/core/CCFun.ml +++ b/core/CCFun.cppo.ml @@ -26,7 +26,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (** {1 Basic Functions} *) +#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2 + +external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply" +external (@@) : ('a -> 'b) -> 'a -> 'b = "%apply" + +#else + let (|>) x f = f x +let (@@) f x = f x + +#endif let compose f g x = g (f x) diff --git a/core/CCFun.mli b/core/CCFun.mli index 40aed09e..59af0e40 100644 --- a/core/CCFun.mli +++ b/core/CCFun.mli @@ -27,7 +27,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (** {1 Basic Functions} *) val (|>) : 'a -> ('a -> 'b) -> 'b -(** Pipeline (naive implementation) *) +(** Pipeline. [x |> f] is the same as [f x]. *) val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c (** Composition *) @@ -35,6 +35,10 @@ val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c val (%>) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c (** Alias to [compose] *) +val (@@) : ('a -> 'b) -> 'a -> 'b +(** [f @@ x] is the same as [f x], but right-associative. + @since NEXT_RELEASE *) + val id : 'a -> 'a (** Identity function *) diff --git a/core/CCString.ml b/core/CCString.cppo.ml similarity index 98% rename from core/CCString.ml rename to core/CCString.cppo.ml index a35c8c3f..3948c8a2 100644 --- a/core/CCString.ml +++ b/core/CCString.cppo.ml @@ -55,11 +55,19 @@ let compare = String.compare let hash s = Hashtbl.hash s +#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2 + +let init = String.init + +#else + let init n f = let buf = Buffer.create n in for i = 0 to n-1 do Buffer.add_char buf (f i) done; Buffer.contents buf +#endif + let length = String.length let rec _to_list s acc i len =