-
Notifications
You must be signed in to change notification settings - Fork 2
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
Survey of other languages that support intersections #14
Comments
If nobody picks this up before next weekend, I'll pick it up then, but I'd like to work on some of the other tangential things here first. Should things like Rust's traits being similar in nature and use to how an intersection of protocols would be used also be included in this? |
Thanks for volunteering! Please include any aspects that you think might be useful in informing the spec for Python. |
📝 TS's guide on intersection is here: https://www.typescriptlang.org/docs/handbook/2/objects.html#intersection-types |
This paper differs from python, treating Any as an unknown element of the set of all types, but defines unions and intersections of types via the [consistent] subtyping relationship rather than by value. https://www.irif.fr/~gc//papers/icfp17.pdf This may be a useful lens for this appendix later, and may also be useful to any future redefinition of Any in Python, as with this definition of unions and intersections, The definition most equivalent here would be that Any is an unknown element in the set of all possible types. With this definition, Any can't be Anything, but it can be anything compatible with all of the other static types that are known. Essentially, there needs to be a possible type that fits in the gap for the use of Any to be sound, even if the programmer has not expressed that type. Examples of how this paper would treat Any, which came up from a discord conversation with @mniip Edit: Removed an example, see post below that goes into more clear detail on what this paper says for Any & T. |
In Kotlin T & Any is a non-nullable generic type. (essentially, all T and all of it's possible subtypes) https://kotlinlang.org/spec/type-system.html#intersection-types Kotlin also handles some cases that arise in intersections by approximating some types which may otherwise not be directly denotable by users with a specific set of rules here: https://kotlinlang.org/spec/type-system.html#type-approximation |
Might be useful for the appendix. It's a little more general, but related to some of the sticking questions. https://github.com/rust-lang/rfcs/blob/master/text/1210-impl-specialization.md#hazard-interactions-with-type-checking |
for the assignment based on y: Any, z: A & B, A&B impossible, Any: Never. It appears that you think this follows out of the formal relation between A GType and set of STypes, but I would appreciate an explanation of what you think the conclusion here is that doesn't use a "python what-if" as an example as It is hard to be sure any leaps are soundly shown. If it was only this example, it would be entirely correct, but there's more to showing it to be correct than this, even if it looks obvious. If you're going the formal route, you need to show all your work, I know you know that. As a result of that, this may not be a good example for the appendix. I don't want to say that your summation of what this means is wrong, it very well could be correct, but I think you need a little more substance to show to have it be checked as correct as well. In particular
I think this is slight misstatement, but it might be equivalent, I'd need to work it out. If you're mentally mapping what was It's a really subtle difference, and it may or may not matter formally, but you have to check that. |
I think it helps to be a little more specific here. https://repositorio.uchile.cl/bitstream/handle/2250/140079/Abstracting-Gradual-Typing.pdf expands on that notion and proposes a set-theoretic semantics for gradual types. We have the universe of static types that values actually range over, and then we have the universe of gradual types that extends the static types with Finally, the paper in question, https://www.irif.fr/~gc/papers/icfp17.pdf , extends these semantics to include union and intersection types. Of extreme importance is the fact that unions and intersections are connectives for the static types. We use them to more accurately describe a set of values, rather than to describe the partial information known about a gradual type. The counterintuitive nature of Now for the example: x : Literal[1] | (Literal[2] & Any) No matter what the programmer substitutes for By playing the same covariance/contravariance trick with |
To avoid confusion, note that Kotlin's Additionally confusing is the fact that Scala's AFAICT Kotlin's |
As we've come to a point where all of the options we are giving consideration of any kind to only differ in the overlapping portion of an intersection:
|
Closing this for now, the most useful takeaways from this are in the WIP draft now. Can reopen if we think more comparisons should be drawn. |
Numerous other programming languages (including some that support gradual typing) provide support for intersections. It would be instructive to learn from these other languages. How did they solve certain problems (e.g. intersection with
Any
)? How do they teach the concept to their developers?Would someone like to volunteer to do a survey and a summary of learnings? This could help inform some of the discussions and design tradeoffs.
The summary could also be included as an appendix to the PEP, like I did for PEP 695. Such a survey would bolster confidence in the design and increase the likelihood of the PEP's acceptance.
The text was updated successfully, but these errors were encountered: