Skip to content
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

Open
wants to merge 15 commits into
base: mlscript
Choose a base branch
from

Conversation

noordahx
Copy link

@noordahx noordahx commented Jul 8, 2024

draft pr

@@ -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
Copy link
Author

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?

Copy link
Contributor

@LPTK LPTK Sep 16, 2024

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.

@noordahx noordahx marked this pull request as ready for review September 15, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants