If I want a function that subtracts an int
argument from the number 2, I can do
let two_minus = (-) 2
But what if I want a function that subtracts 2 from an int argument?
In Haskell, I can do
let minus2 = flip (-) 2
But in Ocaml 4.02, flip
is not part of the standard library.
For now, I've settled on
let minus2 = (+) ~-2
which adds negative 2 to an int
argument. I find it looks cleaner than
let minus2 = fun x -> x-2
... or at least it takes less characters.
Is there a better, more idiomatic way?