Skip to content

Simplify type conversion model #429

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

Open
braxtonmckee opened this issue Feb 1, 2023 · 0 comments
Open

Simplify type conversion model #429

braxtonmckee opened this issue Feb 1, 2023 · 0 comments

Comments

@braxtonmckee
Copy link
Collaborator

Right now we have a complicated hierarchy of conversion types, ranging from Signature to Upcast to ImplicitContainers to New. Its more complicated than we really need and supports a use case we don't care about, at the cost of complexity and poor performance, both in the compiler and in the interpreter. Matching a function signature should be one shot and clear, not a multiple-pass process.

To do this, we should end up with three conversion levels: Signature, Implicit, and New. Signature means change nothing about the object - it can only do things like unwrap an 'int' that's known as 'object', or pack an int into an object. New means create a new instance however you can - including converting an int -> str, and 'Implicit' means you can cast untyped containers to typed containers.

In this model, f(x: int) won't accept 1.5 or 1.0, and f(x: TupleOf(OneOf(None, int)) won't accept TupleOf(int), but would try to coerce 'tuple'. In practice, we've found that we don't really want to rely on type-conversion to pick which implementation of a function we use, since that tends to be hard to predict. So instead, we want to support minimal conversion, but still allow promotion of untyped data to typed data, since that allows for more idiomatic usages and can often be implemented efficiently.

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