OCaml: applying second argument first(higher-order functions)
functional-programming, higher-order-functions, ocaml, readability
Solution
In Haskell, there's a function `flip` for this. You can define it yourself:
let flip f x y = f y x
Then you can say:
other_func (func 5)
third_func (flip func "abc")
Flip is defined in Jane Street Core as `Fn.flip`. It's defined in OCaml Batteries Included as `BatPervasives.flip`. (In other words, everybody agrees this is a useful function.)
Problem
I defined a higher-order function like this: ``` val func : int -> string -> unit ``` I would like to use this function in two ways: ``` other_func (func 5) some_other_func (fun x -> func x "abc") ``` i.e., by making functions with one of the arguments already defined. However, the second usage is less concise and readable than the first one. Is there a more readable way to pass the second argument to make another function?