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

Implement return type "inference" for functions at call sites #25

Closed
polybuildr opened this issue May 10, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@polybuildr
Copy link
Owner

commented May 10, 2017

No description provided.

@polybuildr polybuildr added this to the 0.1.0 milestone May 10, 2017

@bollu

This comment has been minimized.

Copy link
Contributor

commented May 10, 2017

Regarding this and #24, I strongly suggest not going down the route and trying to monkey patch a type system.

Implement any of:

or some flavour thereof.

@polybuildr

This comment has been minimized.

Copy link
Owner Author

commented May 11, 2017

While I appreciate the reliability and tried-and-testedness of using an existing proven type inference algorithm, for a few reasons I don't want to proceed with this in 0.1.0.

Firstly, and probably most significantly, I have a lot of time consuming reading up to do on these algorithms and the background theory, which I don't want to do before this first release.

Secondly, at first glance, I feel like there will need to be some changes to the algorithms anyway, primarily because I feel like they were designed for static/strict type systems (functions can only return a certain type, no unions, variables once bound cannot change type, etc.) and if I'm right it would mean even more time consumed before this is done.

Thirdly, the current type system is really very simple. There are only two levels of types: concrete single types or the Any type. Polymorphism is basically nonexistent. Given this, I'm not sure that a more comprehensive type checking algorithm is strictly necessary as of now. (I'm even considering running the current implementation through a theorem prover just to see what happens :P)

Finally, 0.1.0 was about filling in gaps in the existing features. Type checking and inference (read: propagation) work as of now, and at the return statements, I even know the type being returned, but this does not propagate to the caller. This seems like a gap that should be bridged before 0.1.0, and hence I'd prefer just filling in the existing typechecker. Filed #26 for further investigation.

@polybuildr

This comment has been minimized.

Copy link
Owner Author

commented May 12, 2017

Considering the above comments as well as the haste in which 00dee25 was written, I'm working on removing type annotations/hints and instead only trying to infer. This will probably simplify and shorten the code significantly, making it easier to edit the typechecker in a future release.

polybuildr added a commit that referenced this issue May 14, 2017

Massively refactor return type checking, inferred instead of explicit
- Remove enum ConstraintType, remove explicit type annotations.
- Identify return statements in function bodies, and use them to infer
  the return type for each call site (or rather, for each unique set
  of argument types).
- Correctly use the implied `return;` at the end of functions that are
  not unconditionally returning a value. Still TODO: give the
  FunctionReturnsMultipleTypes error in this case.

Closes #25.

polybuildr added a commit that referenced this issue May 14, 2017

Massively refactor return type checking, inferred instead of explicit (
…#33)

- Remove enum ConstraintType, remove explicit type annotations.
- Identify return statements in function bodies, and use them to infer
  the return type for each call site (or rather, for each unique set
  of argument types).
- Correctly use the implied `return;` at the end of functions that are
  not unconditionally returning a value. Still TODO: give the
  FunctionReturnsMultipleTypes error in this case.

Closes #25.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.