make some functions in CCFun and CCString depend on ocaml version

This commit is contained in:
Simon Cruanes 2014-11-04 15:48:14 +01:00
parent 5c559c2099
commit 611086e6ab
4 changed files with 25 additions and 3 deletions

4
_oasis
View file

@ -8,7 +8,7 @@ LicenseFile: LICENSE
Plugins: META (0.3), DevFiles (0.3) Plugins: META (0.3), DevFiles (0.3)
OCamlVersion: >= 4.00.1 OCamlVersion: >= 4.00.1
BuildTools: ocamlbuild BuildTools: ocamlbuild
AlphaFeatures: ocamlbuild_more_args, compiled_setup_ml AlphaFeatures: compiled_setup_ml
Synopsis: A modular standard library focused on data structures. Synopsis: A modular standard library focused on data structures.
Description: Description:
@ -49,7 +49,7 @@ Library "containers"
CCKList, CCInt, CCBool, CCArray, CCOrd, CCIO, CCKList, CCInt, CCBool, CCArray, CCOrd, CCIO,
CCRandom, CCKTree, CCTrie, CCString, CCHashtbl, CCRandom, CCKTree, CCTrie, CCString, CCHashtbl,
CCFlatHashtbl, CCSexp, CCMap CCFlatHashtbl, CCSexp, CCMap
BuildDepends: cppo XMETARequires: cppo
FindlibName: containers FindlibName: containers
Library "containers_string" Library "containers_string"

View file

@ -26,7 +26,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Basic Functions} *) (** {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 (|>) x f = f x
let (@@) f x = f x
#endif
let compose f g x = g (f x) let compose f g x = g (f x)

View file

@ -27,7 +27,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Basic Functions} *) (** {1 Basic Functions} *)
val (|>) : 'a -> ('a -> 'b) -> 'b 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 val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
(** Composition *) (** Composition *)
@ -35,6 +35,10 @@ val compose : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
val (%>) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c val (%>) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
(** Alias to [compose] *) (** 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 val id : 'a -> 'a
(** Identity function *) (** Identity function *)

View file

@ -55,11 +55,19 @@ let compare = String.compare
let hash s = Hashtbl.hash s let hash s = Hashtbl.hash s
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2
let init = String.init
#else
let init n f = let init n f =
let buf = Buffer.create n in let buf = Buffer.create n in
for i = 0 to n-1 do Buffer.add_char buf (f i) done; for i = 0 to n-1 do Buffer.add_char buf (f i) done;
Buffer.contents buf Buffer.contents buf
#endif
let length = String.length let length = String.length
let rec _to_list s acc i len = let rec _to_list s acc i len =