Permalink
Browse files

Add |> and @@ operators to Pervasives

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13739 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
1 parent 9b53f8b commit ace0205b6499ffdae4588cfdd640c45855217a8f @lefessan lefessan committed Jun 3, 2013
View
@@ -38,6 +38,7 @@ Compilers:
Standard library:
- PR#5986: new flag Marshal.Compat_32 for the serialization functions
(Marshal.to_*), forcing the output to be readable on 32-bit hosts.
+- Add optimized composition operators |> and @@ in Pervasives
Runtime system:
* PR#6019: more efficient implementation of caml_modify() and caml_initialize().
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
@@ -26,6 +26,11 @@ let invalid_arg s = raise(Invalid_argument s)
exception Exit
+(* Composition operators *)
+
+external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply"
+external ( @@ ) : ('a -> 'b) -> 'a -> 'b = "%apply"
+
(* Comparisons *)
external (=) : 'a -> 'a -> bool = "%equal"
View
@@ -22,6 +22,11 @@ let invalid_arg s = raise(Invalid_argument s)
exception Exit
+(* Composition operators *)
+
+external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply"
+external ( @@ ) : ('a -> 'b) -> 'a -> 'b = "%apply"
+
(* Comparisons *)
external ( = ) : 'a -> 'a -> bool = "%equal"
View
@@ -136,6 +136,20 @@ external ( or ) : bool -> bool -> bool = "%sequor"
(** @deprecated {!Pervasives.( || )} should be used instead.*)
+(** {6 Composition operators} *)
+
+external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply"
+(** Reverse-application operator: [x |> f |> g] is exactly equivalent
+ to [g (f (x))].
+ @since 4.01
+*)
+
+external ( @@ ) : ('a -> 'b) -> 'a -> 'b = "%apply"
+(** Application operator: [g @@ f @@ x] is exactly equivalent to
+ [g (f (x))].
+ @since 4.01
+*)
+
(** {6 Integer arithmetic} *)
(** Integers are 31 bits wide (or 63 bits on 64-bit processors).

0 comments on commit ace0205

Please sign in to comment.