[Feature Request] Support function overloading outside of classes
I noticed codon does not mangle names, which is what canonically allows C++ to overload anything.
For example, it would be cool if I could drop the "2" from the second fn name, something I can't do in Python because it lacks static typing:
def make_fs(disk: str) -> List[int]:
fs = []
id = 0
for i, x in enumerate(disk):
x = int(x)
if i % 2 == 0:
fs += [id] * x
id += 1
else:
fs += [-1] * x
return fs
def make_fs2(disk: str, loc: Array[int], size: Array[int]) -> List[int]:
fs = []
id = 0
for i, x in enumerate(disk):
x = int(x)
if i % 2 == 0:
loc[id] = len(fs)
size[id] = x
fs += [id] * x
id += 1
else:
fs += [-1] * x
return fs
If I rename both functions the same make_fs and print the signature:
print(make_fs.__name__)
it seems only the last defined is registered:
make_fs[str,Array[int],Array[int]]
while if I just swap the order in which they are defined in the file, I can change the final implementation:
make_fs[str]
I understand why this makes sense, but it feels very interpreted-like, and not compiled-like.
I put the [Feature Request] tag on this so that the issue makes more sense, but ofc if this is not a request, especially if there are higher priorities =), so feel free to tag or close this
Just putting ideas on the radar
You can already do this; use @overload and it should work (see https://github.com/exaloop/codon/blob/develop/stdlib/itertools.codon for some examples).