-
Notifications
You must be signed in to change notification settings - Fork 30
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
SIP-69: Existential containers #101
base: main
Are you sure you want to change the base?
Conversation
``` | ||
|
||
Defining `Polygon` as a type class rather than an abstract class to be inherited allows us to retroactively state that squares are polygons without modifying the definition of `Square`. | ||
Sticking to subtyping would require the definition of an inneficient and verbose wrapper class. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sticking to subtyping would require the definition of an inneficient and verbose wrapper class. | |
Sticking to subtyping would require the definition of an inefficient and verbose wrapper class. |
Defining `Polygon` as a type class rather than an abstract class to be inherited allows us to retroactively state that squares are polygons without modifying the definition of `Square`. | ||
Sticking to subtyping would require the definition of an inneficient and verbose wrapper class. | ||
|
||
Alas, type classes offer limited support for type erasure–the eliding of some type information at compile-time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean elided at runtime, I think? maybe I misunderstand, but also, I don't know why type erasure is relevant at all?
|
||
## Proposed solution | ||
|
||
The problems raised above can be worked around if, instead of using generic parameters with a context bound, we use pairs bundling a value with its conformance witness. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problems raised above can be worked around if, instead of using generic parameters with a context bound, we use pairs bundling a value with its conformance witness. | |
The problems raised above can be worked around if, instead of using generic parameters with a context bound, we use pairs bundling each value with its conformance witness. |
xs.maxByOption((a) => a.witness.area(a.value)) | ||
``` | ||
|
||
The type `AnyPolygon` conceptually represents a type-erased polygon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I don't understand why we're talking about type erasure here. Maybe it makes sense somehow, but it's not explained sufficiently for me to follow it.
Save for the implicit addition of `.value` on method selection when the receiver is an instance of `Containing[C]`, this proposal requires no change in the language. | ||
As a result, it has no backward binary or TASTy compatibility consequences. | ||
|
||
### Feature Interactions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Feature Interactions | |
### Feature interactions |
|
||
One problem not addressed by the proposed encoding is the support of multiple type classes to form the interface of a specific container. | ||
For example, one may desire to create a container of values whose types conform to both `Polygon` _and_ `Show`. | ||
We have explored possible encodings for such a feature but decided to remove them from this proposal, as support for multiple type classes can most likely be achieved without any additional language change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intent to answer this more fully before the proposal comes to a vote? Or do we expect it to remain an open question until some future iteration after the SIP lands?
For example, one may desire to create a container of values whose types conform to both `Polygon` _and_ `Show`. | ||
We have explored possible encodings for such a feature but decided to remove them from this proposal, as support for multiple type classes can most likely be achieved without any additional language change. | ||
|
||
Another open question relates to possible language support for shortening the expression of a container type and/or value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto on whether this might get filled in soon, or it's definitely a "someday" thing?
|
||
## Related work | ||
|
||
Swift support existential containers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift support existential containers. | |
Swift supports existential containers. |
No description provided.