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

Implement generics #154

Open
Tracked by #1600
certik opened this issue Feb 21, 2022 · 6 comments
Open
Tracked by #1600

Implement generics #154

certik opened this issue Feb 21, 2022 · 6 comments

Comments

@certik
Copy link
Contributor

certik commented Feb 21, 2022

We need to allow writing generic functions (templates) and template constraints.

One idea that we can explore is to also support something like: #152 (comment):

>>> def str(val: i32 | f64):
...   # "isinstance" type guard
...   if isinstance(val, i32):
...     # type of `val` is narrowed to `i32`
...     return str_int(val)
...   elif isinstance(val, f64):
...     # else, type of `val` is narrowed to `f64`
...     return str_float(val)
@certik certik mentioned this issue Feb 21, 2022
9 tasks
@Smit-create
Copy link
Collaborator

This should now be possible with overload decorator.

@certik
Copy link
Contributor Author

certik commented Mar 13, 2022

This particular case can be. We still need generics/templates.

The overload in a sense is a subset of generics: you provide specific implementations ahead of time. The templates do not provide specific implementations, the compiler instantiates them.

@certik certik mentioned this issue Mar 21, 2023
38 tasks
@Aser-Abdelfatah
Copy link

Was this picked up by any person? Or is it still open for contribution?

@certik
Copy link
Contributor Author

certik commented Sep 25, 2024

Yes, it's still open. We have quite solid generics in libasr thanks to LFortran, and we should hook them into LPython.

@Aser-Abdelfatah
Copy link

Hi,
I'm doing more research into this. I found some generics implemented in GSoC 2022. I'd just appreciate if there were more details on which generics have higher priority or where to start

@certik
Copy link
Contributor Author

certik commented Nov 8, 2024

They are implemented in LFortran, you can start here: https://docs.lfortran.org/en/asr/generics/.

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

No branches or pull requests

3 participants