Skip to content

Consider easy case of type inference #2000

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
rebcabin opened this issue Jun 22, 2023 · 2 comments
Open

Consider easy case of type inference #2000

rebcabin opened this issue Jun 22, 2023 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@rebcabin
Copy link
Contributor

Not suggesting a big, heavy, system of type inference, but perhaps we can easily do this:

    lower_case_alpha_range = ReRange(ord('a'), ord('z'))
    upper_case_alpha_range = ReRange(ord('A'), ord('Z'))
    digit_range            = ReRange(ord('0'), ord('9'))
    underscore             = ReRange(ord('_'), ord('_'))
    special_AT             = ReRange(ord('@'), ord('@'))
    special_TILDE          = ReRange(ord('~'), ord('~'))

instead of this (currently required):

    lower_case_alpha_range : ReRange = ReRange(ord('a'), ord('z'))
    upper_case_alpha_range : ReRange = ReRange(ord('A'), ord('Z'))
    digit_range            : ReRange = ReRange(ord('0'), ord('9'))
    underscore             : ReRange = ReRange(ord('_'), ord('_'))
    special_AT             : ReRange = ReRange(ord('@'), ord('@'))
    special_TILDE          : ReRange = ReRange(ord('~'), ord('~'))
@rebcabin rebcabin added enhancement New feature or request question Further information is requested labels Jun 22, 2023
@certik
Copy link
Contributor

certik commented Jun 22, 2023

Related to #305.

I would be very conservative here. As a first step we can consider:

  • ReRange is a struct or a class (not a user function)
  • The type of the ReRange constructor is ReRange (in Python this is not the case in general, for example in SymPy Add(x, x) -> Mul(2, x))

LPython will verify that both are true, otherwise give an error message. The second point right now is always true, but if we later support metaclasses, then they could return another type, so we would have to check that.

I think the goal is that it must be obvious for a human reader to immediately know the types of everything just by looking at some part of the code.

@rebcabin
Copy link
Contributor Author

Yes. I believe Java landed on this same idea (types obvious at a glance) at the beginning of their type-inference days, but I'm not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants