-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional arguments #223
base: mlscript
Are you sure you want to change the base?
Optional arguments #223
Conversation
@@ -9,8 +9,8 @@ fun (??) oops(a, b) = a + b | |||
//│ = 3 | |||
|
|||
|
|||
fun f1(a?: Int, b?: Int) = a + b | |||
//│ fun f1: (a: (Int)?, b: (Int)?) -> Int | |||
fun f1(aOpt?: Int, bOpt?: Int) = aOpt + bOpt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LPTK how can I handle this case?
should it return an error requiring a
and b
defined before a + b
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of this approach is that if your parameter x
of type T
is optional (annotated with ?
), then while the corresponding parameter type remains T
when viewed from the outside (but of course, the parameter is still marked as optional), as in (? T) -> Int
, the visible type of x
inside the body is T | undefined
. That's all we need for the feature to work correctly.
draft pr