Implement generics
We need to allow writing generic functions (templates) and template constraints.
One idea that we can explore is to also support something like: https://github.com/lcompilers/lpython/pull/152#issuecomment-1047082741:
>>> 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)
This should now be possible with overload decorator.
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.
Was this picked up by any person? Or is it still open for contribution?
Yes, it's still open. We have quite solid generics in libasr thanks to LFortran, and we should hook them into LPython.
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
They are implemented in LFortran, you can start here: https://docs.lfortran.org/en/asr/generics/.