[swift-evolution] Union instead of Optional

Thorsten Seitz tseitz42 at icloud.com
Mon May 16 04:58:52 CDT 2016

Yes, enums are like explicit named type unions whereas ad hoc type unions can be useful exactly because they are ad hoc.
It is kind of like named functions vs. anonymous functions. Both have their place.

Ceylon makes tremendous use of union and intersection types. While they don’t have enums in the Swift sense they have something very similar, so they certainly make use of both approaches, too. Like I said both have their place and introducing type unions shouldn’t replace enums (unless we should discover that type unions can do all that enums do, e.g. with extensions it might even be possible to add methods to type unions in Swift).


> Am 15.05.2016 um 13:07 schrieb Tino Heth via swift-evolution <swift-evolution at swift.org>:
> I don't know if there has been any internal discussion about using union-types instead of enums, but afaics, there are no obvious downsides for that approach.
>> I'm a little curious as to why union types keep on coming up, when enums can do everything they can and much more (methods, constraints on generic types, conformance to protocols).
> Are there any strong reasons why those features would not be possible with union types?
> There has been a discussion started because it is a little bit cumbersome to create enum-properties (and methods).
> With unions, there would be no need for all those switch-statements, and would be possible to configure cases in a central location.
> There has also been a proposal for "anonymous enums", which could be modeled with unions in a very elegant way.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160516/ea56f916/attachment.html>

More information about the swift-evolution mailing list