-
Notifications
You must be signed in to change notification settings - Fork 0
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
DSL generics #24
Comments
Trying this today to see if it works; otherwise this will be deemed impossible until static semantics are implemented in Statix |
Status update: implementing static semantics in Statix since end of November. Currently still translating existing semantics, but it seems likely that generics can easily be implemented with Statix. |
Clarification on previous comment: I expect that generics will be hard, but mostly due to the inherent complexity of generics, not due to the incidental complexity of Statix |
Blocked by ambiguity in #208 |
There is an implementation to resolve #208 (syntax was changed from Still to do: add a few compiler tests so that there is some protection against regressions. |
Blocked again by syntax issues, this time by #237. |
Implemented, currently opening PR |
Generics for PIE DSL
Full generics cannot be implemented in NaBL2, but some parts can.
This proposal aims to implement generics for data types.
use cases
JSGLR1ParseResult.getAst()
returns anOptional<T>
Result<T, E>
assertEquals(expected: T, actual: T, message: string) -> unit
syntax
New type:
Type.GenericTy = [[ID]<{[ID] ", "}+>]
. Exactly the same as Java, e.g.Result<T, E>
. Can be used everywhere a type is used.Functions gain the ability to specify generic type parameters:
func createOk<T: Object>(val: T) -> Result<T, Exception> = foreign java mb.common.result.Result#ofOk
func id<T>(val: T) -> T = val
Call a generic function:
val result = createOk<Foo*>([createFoo()]);
Requirement to explicitly add types may be lifted in the future (presumably requires statix analysis though).
Static semantics
For now,
data Foo<Bar>
:Bar
must be a valid data type, it is not a generic data type.Later: allow
data Foo<T: Language>
. If the generic type parameter adds a supertype it is a generic parameter, without a parameter it is specific. AllowT: _
to use TopTy as parameter.Even later: deprecate
data Foo<T>
. After deprecation,data Foo<T>
becomes syntactic sugar forFoo<T: _>
func createOk<T: Object>(...)
Code generation:
[todo]
Issues
[todo]
The text was updated successfully, but these errors were encountered: