This is undoubtedly a FAQ many times over, so feel free to point me to discussion elsewhere. “no-value argument” in the title is not a very good term. I wasn’t sure what to call this.
When defining a function, I often feel that it would be convenient to be able to define an optional argument that doesn’t need to be followed by a colon and a value. The mere presence of the optional argument in the function call would be enough to make something different happen. Perhaps such arguments would automatically have the type
unit option. For example, if
?? were syntax for defining such flag arguments, I could do this:
let f ??double x = match double with | None -> x | Some () -> 2 * x
f 3 would return 3, while
f ~double 3 would cause
Some () to be passed to the function, which would return 6.
I’m sure I’m not the first person to think of this, but the idea has apparently been rejected. Are there any very significant reasons for that? Maybe it’s just that it’s felt that the cost of adding, say,
:() to an argument is so small that it’s not worth changing the language.
(I don’t think that no-value arguments would present any complications for partial application that are not already raised by the existing optional argument system, but maybe I’m missing something.)