Is there an infix function composition operator in OCaml?

The answer here is the same as for flip :-). Function composition isn’t defined in the OCaml standard library. In this case, it isn’t something I miss once in a while, I miss it all the time.

The OCaml Batteries Included project defines function composition (in the order you give) using the operator -| in the BatStd module. As lukstafi points out (see below), this operator will apparently change to % in a future release of Batteries. (I’ve verified this in their source tree.)

As far as I can see, the Jane Street Core project doesn’t define a function composition operator. It defines a function compose in the Fn module.

Leave a Comment