-
Notifications
You must be signed in to change notification settings - Fork 122
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
Nested structs and functions within structs #72
Comments
Why using the type Closure = () => i32; |
It's easier to compile this way. |
I assumed, but I think that introducing a new keyword is problematic. Maybe this can be solved with a special generic? |
How would a generic function type work for this? Could you be more specific, what syntax would be an alternative? For background, I initially did use regular functions types for closures, but the two have fundamentally different representations in the binary. This means that syntax becomes ambiguous, where a function, for example, can return either a closure or a function pointer. By extension, any use of a return value from a function like this is now also ambiguous. All this means is that types have to be specific to the thing they represent. If there is a way to express a closure being different with existing syntax, I'm all for it though. It also may be possible to omit the |
You can mark external functions explicitly: -type Log = (i32) => void;
+type Log = External<(i32) => void>; |
Cool, so are you suggesting that we should have a built-in type for -type lambda Closure = () => i32;
+type Closure = Lambda<() => i32>; or -type lambda Closure = () => i32;
+type FunctionType = () => i32;
+type Closure = Lambda<FunctionType> I personally have not seen this particular use of generics before, but this could work. Would need a type parser change/PR but I like it 👍 |
Might I also suggest replacing the 'type' keyword for 'lambda'. For example 'lambda Func = () => i32’ Note: I'm on my phone and I'm unsure how the syntax style formatting works. |
Goal
Allow for nested structs and functions within structs.
Overview
Depends on (#28)
Closures are cool, but to be useful you'd want to return an object/struct with a closure or another struct as a field.
Basically, this syntax should be possible
This should make the syntax much more expressive and allow for a wide range of applications.
Acceptance Criteria
The text was updated successfully, but these errors were encountered: