[swift-evolution] [Proposal] Union Type
davesweeris at mac.com
Fri Jul 1 13:59:11 CDT 2016
It’s already on that list. That’s what Joe was quoting from earlier.
Everybody (I hope) understands the “something the type system cannot […] support” part, but if the “should not” bit were expanded a bit so that people would know why it shouldn’t be supported…
The closest I ever saw to a reason was a reply from back in the “Contiguous Variables (A.K.A. Fixed Sized Array Type)” thread (http://article.gmane.org/gmane.comp.lang.swift.evolution/6363)
> Types aren't just bags of operations, which means that taking the intersection of arbitrary types isn't meaningful. Similarly, generics aren't templates to be instantiated, meaning that there has to be a run-time representation of a "value of intersection type".
> The constructs that carries the right meaning in Swift are protocols, and in theory you could intersect the protocols of the various types. In practice, though, the current model doesn't have a good way to actually do this, since not all protocols can be used as types of values, and finding the protocol-intersection of N types is a needless amount of extra work for the compiler anyway.
Which, at least to me, isn’t very convincing. In the author’s defense, I don’t think the post was intended to be a rigorous rebuttal of the idea.
- Dave Sweeris
> On Jul 1, 2016, at 12:47 PM, L. Mihalkovic via swift-evolution <swift-evolution at swift.org> wrote:
> @core team: should the be added to the list of common rejections for now or does it stand a chance in the next 2 or 3 versions?
> (From mobile)
> On Jul 1, 2016, at 11:06 AM, Cao Jiannan via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md <https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md>
>> I'm now officially proposal the union type feature for Swift. Please see:
>> https://github.com/apple/swift/commit/eb7311de065df7ea332cdde8782cb44f9f4a5121 <https://github.com/apple/swift/commit/eb7311de065df7ea332cdde8782cb44f9f4a5121>
>> Add union type grammar, represents the type which is one of other types.
>> var stringOrURL: String | URL = "https://www.apple.com <https://www.apple.com/>"
>> I would be thankful if someone support this idea and give some advice. Thanks!
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution