Scala allows function parameters to be call-by-name using the '=>' syntax. For example, the boolean and function can be defined as:
def and(x: Boolean, y: => Boolean): Boolean =
if (x) y else false
The second parameter is call-by-name. This ensures the expected "short-circuiting" behaviour – if x is false, y will not be evaluated at all.
In general, this is useful for functions where a parameter might not be used at all.
How can this be done in OCaml?
I am aware that OCaml has constructs for lazy evaluation, but it is not clear to me if and how these could be used for call-by-name parameter passing.