[swift-evolution] Fwd: Union instead of Optional

Cao Jiannan frogcjn at 163.com
Sat May 14 21:27:52 CDT 2016


> 2016-2-16 GMT+8 14:36:28
> Hi all,
> 
> I think the best way to solve the either problem is to separate it from generic. 
> Optional and Either shouldn’t work the same way of generic type. 
> It’s just a represent of multiple type in one location.
> 
> Using an old friend, Union in C.
> union {
> 	case firstType
> 	case secondType
> }
> 
> This is the final solution for the sub typing problem of optional.


It’s kind of same idea of TypeScipt 2, at 46:21 in this video.

https://channel9.msdn.com/Events/Build/2016/B881 <https://channel9.msdn.com/Events/Build/2016/B881>




> 
> 
> 
> A  == union(A,A)
> union(A,B) == union(B,A)
> B == union(B,B)
> 
> B is subtype of union(A,B)
> A is subtype of union(A,B)
> union(A,B,C) is subtype of union(A,B,C,D,…)
> 
> suppose 
> a is subclass of A
> b is subclass of B, then
> 	union(a,B) is subtype of union(A,B)
> 	union(A,b) is subtype of union(A,B)
> 	union(a,b) is subtype of union(a,B)
> 	union(a,b) is subtype of union(A,b)
> 
> union can have as many case as possible. e.g., union(A,B,C,D,…)
> 
> So the Optional<UITableView> should be union(UITableView, None)
> and Optional<MyTableVIew> should be union(MyTableView, None), which is subclass of union(UITableView, None)
> 
> This is a final rational solution. I think.
> 
> -Jiannan
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160515/e7f8a12d/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ???? 2016-05-15 10.20.36.png
Type: image/png
Size: 423597 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160515/e7f8a12d/attachment-0001.png>


More information about the swift-evolution mailing list