[swift-evolution] Proposal: An Either Type in the STL

Thorsten Seitz tseitz42 at icloud.com
Sun Dec 13 02:48:05 CST 2015


> Am 12.12.2015 um 20:08 schrieb Joe Groff <jgroff at apple.com>:
> 
> 
>>> On Dec 12, 2015, at 10:58 AM, Thorsten Seitz <tseitz42 at icloud.com> wrote:
>>> 
>>> 
>>> Am 12.12.2015 um 19:01 schrieb Joe Groff via swift-evolution <swift-evolution at swift.org>:
>>> 
>>> (T | T | U | V) and (U | T | V) would be distinct types
>> 
>> That would be unexpected. I’d expect them to be the same type.
>> 
>> In Ceylon I can do the following without problems:
>> String|String|Integer foo = 1;
>> Integer|String bar = foo;
>> or
>> interface Parent {}
>> interface ChildA satisfies Parent {}
>> interface ChildB satisfies Parent {}
>> ChildA a = childA();
>> ChildB b = childB();
>> Parent p1 = a;
>> ChildA|Parent p2 = b;
>> Parent p3 = if (x) then a else b;
>> Everything fits nicely as expected.
> 
> I agree, but making this work massively complicates the type system, as John noted.

Certainly, but at the same time much more powerful!

And the Ceylon type system has recently been made available as a module with Apache 2 license, so it should be possible to check how they have solved problems (although I fear that Swift's non attribution license extension might be a problem here).

-Thorsten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151213/78bab9bc/attachment.html>


More information about the swift-evolution mailing list