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
def rec fact(~n=0)
if n == 0 then
1
else
n * fact(n=(n-1))
end
end
It gives rise to the error
Error 5: this value has type
(n : _, ...) -> _ (inferred at line 7, char 8-13)
but it should be a supertype of the type of the value at line 3 char 0 - line 9 char 3
(?n : _) -> _
because when the function fact is applied to the label n in the middle, we infer that it has a non-optional argument labeled n: we cannot guess that it is going to be optional yet...
This means in practice that we cannot make recursive functions with optional arguments (and I have more convincing examples than factorial...).
I don't see a way out without introducing a new syntax for using optional arguments when we really want to mean that they are optional. In OCaml, the way out is to use option types, which we don't have...
Consider the following code:
It gives rise to the error
because when the function
fact
is applied to the labeln
in the middle, we infer that it has a non-optional argument labeledn
: we cannot guess that it is going to be optional yet...This means in practice that we cannot make recursive functions with optional arguments (and I have more convincing examples than factorial...).
I don't see a way out without introducing a new syntax for using optional arguments when we really want to mean that they are optional. In OCaml, the way out is to use option types, which we don't have...
@toots any idea / comment ?
The text was updated successfully, but these errors were encountered: