You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
>>>defstr(val: i32|f64):
... # "isinstance" type guard
... ifisinstance(val, i32):
... # type of `val` is narrowed to `i32`
... returnstr_int(val)
... elifisinstance(val, f64):
... # else, type of `val` is narrowed to `f64`
... returnstr_float(val)
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.
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
Activity
Smit-create commentedon Mar 13, 2022
This should now be possible with
overloaddecorator.certik commentedon 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.
Aser-Abdelfatah commentedon Sep 24, 2024
Was this picked up by any person? Or is it still open for contribution?
certik commentedon 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 commentedon Nov 7, 2024
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 commentedon Nov 8, 2024
They are implemented in LFortran, you can start here: https://docs.lfortran.org/en/asr/generics/.