add aliases to deprecated functions from String, add Fun.opaque_identity

This commit is contained in:
Simon Cruanes 2016-05-04 23:12:32 +02:00
parent 790e665441
commit 3190278d86
4 changed files with 54 additions and 0 deletions

View file

@ -15,6 +15,16 @@ let (@@) f x = f x
#endif
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 3
let opaque_identity = Sys.opaque_identity
#else
let opaque_identity x = x
#endif
let compose f g x = g (f x)
let compose_binop f g x y = g (f x) (f y)

View file

@ -65,6 +65,12 @@ val finally2 : h:(unit -> _) -> ('a -> 'b -> 'c) -> 'a -> 'b -> 'c
[h ()] is called whether [f x y] rose an exception or not.
@since 0.16 *)
val opaque_identity : 'a -> 'a
(** [opaque_identity x] is like [x], but prevents Flambda from using [x]'s
definition for optimizing it (flambda is an optimization/inlining pass
in OCaml >= 4.03).
@since NEXT_RELEASE *)
(** {2 Monad}
Functions with a fixed domain are monads in their codomain *)

View file

@ -639,6 +639,26 @@ let exists2 p s1 s2 =
try iter2 (fun c1 c2 -> if p c1 c2 then raise MyExit) s1 s2; false
with MyExit -> true
(** {2 Ascii functions} *)
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 3
let capitalize_ascii = String.capitalize_ascii
let uncapitalize_ascii = String.uncapitalize_ascii
let uppercase_ascii = String.uppercase_ascii
let lowercase_ascii = String.lowercase_ascii
#else
let capitalize_ascii = String.capitalize
let uncapitalize_ascii = String.uncapitalize
let uppercase_ascii = String.uppercase
let lowercase_ascii = String.lowercase
#endif
let pp buf s =
Buffer.add_char buf '"';
Buffer.add_string buf s;

View file

@ -378,6 +378,24 @@ val exists2 : (char -> char -> bool) -> string -> string -> bool
@raise Invalid_argument if the strings have not the same length
@since 0.12 *)
(** {2 Ascii functions}
Those functions are deprecated in {!String} since 4.03, so we provide
a stable alias for them even in older versions *)
val capitalize_ascii : string -> string
(** See {!String}. @since NEXT_RELEASE *)
val uncapitalize_ascii : string -> string
(** See {!String}. @since NEXT_RELEASE *)
val uppercase_ascii : string -> string
(** See {!String}. @since NEXT_RELEASE *)
val lowercase_ascii : string -> string
(** See {!String}. @since NEXT_RELEASE *)
(** {2 Splitting} *)
module Split : sig