-
Notifications
You must be signed in to change notification settings - Fork 39
Fix re-declaration semantics and refine generated code (close #49) #54
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
Conversation
LPTK
left a comment
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.
You implementation has at least one small oversight:
def f: (int & 'a) -> (int & 'a) -> 'a
def f a b = if gt a b then a else b
f 1 2
f x y = x
f 1 3yields:
val f: (int & 'a) -> (int & 'a) -> 'a = (a) => (b) => a > b ? a : b
val f: (int & 'a) -> (int & 'a) -> 'a = (x) => (y) => x
val res: 1 | 2 = 2
val f: 'a -> anything -> 'a = no value
val res: 1 = 1
The output on my side is different from yours. I just pushed the fix. Type check results and execution results should be aligned now. |
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 example input in local_testing.html crashes with:
Runtime error occurred:
SyntaxError: Identifier 'temp' has already been declared
I minimized it to:
class Left[A]: { value: A }
def testVal = Left{ value = 1 }
def res = case testVal of
{ Left -> testVal.value
}PS: You should be doing these basic tests on your own, not wait that I do them myself.
Thanks for pointing it out! I did not consider this case after introducing 8d6800f. I should try to keep this PR atomic. 😅 |
LPTK
left a comment
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.
Okay, this LGTM now. I think we should merge it.
This PR fix #49 and add rename operations to
Scope. Besides, this PR simplify and improve generated code.Fix incorrect class name shadowing
Source MLscript
Generated JavaScript
Translate pattern matches to
?:Source MLscript
Generated JavaScript
Note that we cache the result with a temporary variable if there are more than two case branches in order to prevent duplicated evaluation.