Quantcast
Viewing all articles
Browse latest Browse all 531

Pipeline operator in OCaml [closed]

In my practice of programming in OCaml, I have recently discovered that the following pipeline operator is very useful to create functions.

let (>|) f g x = g (f x)val ( >| ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c = <fun>

I use it to replace codes like:

fun s -> int_of_string s |> Int.hash - : string -> int = <fun>

By the simpler:

int_of_string >| Int.hash- : string -> int = <fun>

The associativity works fine:

int_of_string >| float_of_int >| string_of_float- : string -> string = <fun>

Would that be a valuable improvement of the core language, and if so, how to submit this contribution?


Viewing all articles
Browse latest Browse all 531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>