-
Notifications
You must be signed in to change notification settings - Fork 108
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
Type narrowing proof of concept #577
base: master
Are you sure you want to change the base?
Conversation
Teal Playground URL: https://577--teal-playground-preview.netlify.app |
With Teal being nominal typed rather than structurally typed, I don't think the code for |
Yes that was just an example, it could check that By the way, looks like that |
f361b96
to
3a15d99
Compare
|
3a15d99
to
976480b
Compare
@hishamhm any feedback on this? |
@hishamhm ping is this something that could be included in the project in some form? or will teal follow another direction? typescript-style narrowing? dependent types? |
@fgaz Sorry for not providing proper feedback earlier (for some reason I thought I did?? but I clearly didn't...) I plan to add a way to specialize the behavior of I'm not a fan of such utility types like In any case, this PR is good food for thought! I'll take the functionality you described into account when designing interface support (even if we end up supporting only a subset at first). As such, I think it achieved its goal as a proof-of-concept! |
@hishamhm thanks for the feedback and link, much appreciated! I can see why a utility type is not perfect. For example it can be misused by passing it around carelessly, as it's untied to the value it refers to. But I think specific syntax has even worse drawbacks. Mainly, it isn't first class. In typescript, which has specific I'm actually writing an article about all this and how some limited form of dependent typing would solve the problem neatly, I'll link it when/if I manage to publish it. |
This is a proof of concept of type narrowing à la mypy. It successfully compiles the following teal code:
And thanks to generics, even more complex stuff like
This is just to show how it can work. This minimal implementation has a number of problems:
Is
is hardcoded and a dummy definition has to be providedIs
is a normal record instead of its own type (maybe this is fine though)Booleans are not automatically promoted toIs
Related: #108 #124 #563