Thanks @yawaramin. Yes, I think this idea is a good solution for some contexts. It doesn’t achieve what I wanted in general, though. It’s clean, but for a single use of
~double, it’s more verbose than using
All of the suggestions given so far are helpful given the current version of OCaml.
~double:true, or perhaps better,
~double_it:true, is redundant. That is, the Boolean character of the flag can be built in to its name.
~double:() is more succinct, and only uses three unnecessary characters (as I see it), but it’s confusing because passing unit always seems unnecessary (there is only one argument of that type).
Again, I’m not asserting that value-less optional arguments must be added to the language, but I do think they would be nice. Part of the issue for me is just aesthetics, but another part is that I do a lot of experimentation in toplevel, and extra typing there is more annoying, I find.
(Could I define my own syntax for optional flags using camlp4 or ppx or something like that? I don’t know any of these syntax extension systems, I’m not sure I want to learn them just for a small change that is likely to confuse readers of my code anyway because it’s nonstandard.)
(In general I find that when I suggest additions to a language, or ask why it doesn’t include feature X, most responses suggest workarounds given the current language. That’s not specific to OCaml; I have had the same experience in discussions about at least one other language. This kind of response is certainly helpful in the short run. In some cases I’m already aware of the workarounds, but it doesn’t hurt to spell them out for others. However, that sort of response gives me the the feeling that I’m supposed to think that the language in its current form should be considered to be at a local optimum, and should not be changed–but without any discussion of whether it’s correct that it should not be changed. Usually the change I suggest is simply the addition of a new function. In this case, the suggestion is a bit deeper since it would change syntax.)