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

[Feature Request] Support function overloading outside of classes #615

Open
AndreiMoraru123 opened this issue Dec 9, 2024 · 1 comment

Comments

@AndreiMoraru123
Copy link

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.

@AndreiMoraru123
Copy link
Author

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

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

1 participant