You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are a couple of things about optional args that are not coder-friendly:
Positional args cannot be optional (even if there is just one arg)
The need for "unit" param/arg as a final positional arg even when all args are labelled
Is there no way to make this a nicer experience? Mixing positional and labelled args in general seems a slightly odd allowance, but particularly so if it is causing this "unit" oddness. A necomer to the language (e.g. me a couple of weeks ago) is not going to understand why this is necessary:
Note for the sake of the type system, whenever you have an optional argument, you need to ensure that there's also at least one positional argument (aka non-labeled, non-optional argument) after it. If there's none, provide a dummy unit (aka ()) argument.
The need for "a dummy unit argument" is precisely the kind of quirk that could turn people away from this language. We come here in search of something better than typescript, so if this is going to remain in the language, I think we deserve a more detailed explanation than "for the sake of the type system". What is the trade-off here, what are we gaining in exchange for needing to use the dummy unit arg?
The text was updated successfully, but these errors were encountered:
This can be explored in the context of uncurried types, where the number of arguments is fixed. So if an optional argument is omitted, the intention is clear.
With curried types, the intention is ambiguous, maybe the intention is to provide that extra argument later. In general, even a simpler example is confusing, one with only say 3 mandatory labelled arguments (~x, ~y, ~z) => x+y+z. If you only supply z, that is interpreted as partial application, returning a function that still expects x and y. This is going to surprise a number of users who simply forgot to pass extra mandatory arguments.
With uncurried types, passing only z is an error.
Uncurried types by default are explored in compiler v11, under development.
https://rescript-lang.org/docs/manual/latest/function#optional-labeled-arguments
There are a couple of things about optional args that are not coder-friendly:
Is there no way to make this a nicer experience? Mixing positional and labelled args in general seems a slightly odd allowance, but particularly so if it is causing this "unit" oddness. A necomer to the language (e.g. me a couple of weeks ago) is not going to understand why this is necessary:
The need for "a dummy unit argument" is precisely the kind of quirk that could turn people away from this language. We come here in search of something better than typescript, so if this is going to remain in the language, I think we deserve a more detailed explanation than "for the sake of the type system". What is the trade-off here, what are we gaining in exchange for needing to use the dummy unit arg?
The text was updated successfully, but these errors were encountered: