modular
modular copied to clipboard
[Feature Request] Allow parametric materialization
Review Mojo's priorities
- [X] I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
Allow parametric materialization of nonmaterializable types.
Currently, i'm not aware of any way to get the following behavior:
@nonmaterializable(MyVal[param])
struct MyLit[param: Bool]:
...
struct MyVal[param: Bool]:
...
Or alternatively, a required __materialize__() method when no arguments to @nonmaterializable are given:
@nonmaterializable
struct MyLit[param: Bool]:
fn __materialize__(self) -> MyVal[param]:
return self
...
struct MyVal[param: Bool]:
...
What is your motivation for this change?
I have some use cases for something like this, such as custom generalized complex literals. I don't know the inner workings, so i'm not sure if this would fit into the compilation flow, but if not that's okay.
Any other details?
if something already exists like this, or you think there's a better way to go about it, let me know :]