<div dir="ltr">I think this proposal should stick to the intersection type: a type which inherits from at most one class (multiple inheritance should definitely be a separate proposal) if it conforms to all of one or more specified protocols.<div><br></div><div>The immediate problem I see with a union type is using it. If I'm understanding it right, this would let me define a union type of any<UITextView, UITextField>, to a variable 'textControl'. I might then be able to set 'textControl.text' to a value, regardless of whether it's actually a UITextView or UITextField. But the correct way to do this would be to create a protocol (say) 'HasTextProperty', extend UITextView and UITextField to conform to HasTextProperty, and use that. The intersection type would even let us extend the type safety of 'textControl' to 'all<UIView, HasTextProperty>'.</div><div><br></div><div>The next issue I'd see with the union type is that it's the already proposed Either type.</div><div><br></div><div>-- Ross</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 11, 2016 at 1:10 PM, Maximilian Hünenberger <span dir="ltr"><<a href="mailto:m.huenenberger@me.com" target="_blank">m.huenenberger@me.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div></div><div>I don't see union and intersection types either in the "goals list" or in the "non-goals list". Either way it should be a separate proposal.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>- Maximilian</div></font></span><div><div class="h5"><div><br>Am 11.02.2016 um 09:29 schrieb Thorsten Seitz <<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>>:<br><br></div><blockquote type="cite"><div><div></div><div>Ceylon uses & for intersection types (and | for union types) which I find quite intuitive, meaning a type which conforms to this AND that protocol/type (OR in the case of unions).</div><div><br></div><div>It works like expected, i.e.</div><div>A & B & A == A & B </div><div><br></div><div>or</div><div>typealias A = B & C</div><div>A & C == B & C</div><div>A & D == B & C & D</div><div><br></div><div>class A<T> {</div><div> var x: T & B</div><div>}</div><div><br></div><div>var a: A<C></div><div>a.x has type C & B</div><div><br></div><div>var b: A<B></div><div>b.x has type B</div><div><br></div><div>etc.</div><div><br></div><div>-Thorsten </div><div><br></div><div><br></div><div>Am 10.02.2016 um 14:59 schrieb Ross O'Brien via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:<br><br></div><blockquote type="cite"><div><div dir="ltr">I agree with everything Brent just said.<div>My question would then be: how does this extend?</div><div><br></div><div>Continuing the example:</div><div>'typealias ViewControllerTableViewDataSource = all<UIViewController, UITableViewDataSource>'</div><div><br></div><div>It should then be possible to have a subtype of this which also conforms to UITableViewDelegate.</div><div>So, given the above, this would work:</div><div>'typealias ViewControllerTableViewPackage = all<UIViewController, UITableViewDataSource, UITableViewDelegate>'.</div><div>Would this also work?</div><div>'typealias ViewControllerTableViewPackage = all<ViewControllerTableViewDataSource, UITableViewDelegate>'<br></div><div>Assuming someone defined this typealias: 'typealias TableViewPackage = protocol<UITableViewDataSource, UITableViewDelegate>', would the above also be equivalent to this?:</div><div>'typealias ViewControllerTableViewPackage = all<UIViewController, TableViewPackage>'</div><div><br></div><div>The TableViewPackage protocol, defined above, is considered by Swift to be a 'non-nominal type'. Thus this is illegal:</div><div>'extension TableViewPackage'</div><div>(I don't know why. Perhaps a type conforming to the separate protocols has to opt-in to the combination?)</div><div><br></div><div>However, we can have the following:<br></div><div>'extension UITableViewDelegate where Self : UITableViewDataSource'</div><div>'extension UITableViewDelegate where Self : UIViewController'</div><div>'extension UITableViewDelegate where Self : UIViewController, Self : UITableViewDataSource'</div><div><br></div><div>Similarly we can't currently have this:</div><div>'extension UIViewController where Self : UITableViewDataSource, UITableViewDelegate'</div><div>because UIViewController is not a generic type (and this is part of the original complaint).</div><div><br></div><div>It would be nice to be able to write this out as: 'extension all<UIViewController, UITableViewDataSource, UITableViewDelegate>', even if it's just syntactic sugar for 'extension UITableViewDelegate where Self : UIViewController, Self : UITableViewDataSource'.</div><div><br></div><div>-- Ross</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 10, 2016 at 1:44 PM, Maximilian Hünenberger <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In the thread "Partially constrained protocols" we have discussed a similar approach using where clauses:<br>
<br>
protocol<MyProtocol where Self: UIViewController><br>
<br>
- Maximilian<br>
<div><div><br>
Am 10.02.2016 um 14:00 schrieb Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>:<br>
<br>
>> So, I definitely think there is room for improvement here… how about recycling the inheritance syntax?<br>
>><br>
>> let controller: (UIViewController, UITableViewDatasource)<br>
><br>
> This declares a tuple containing a UIViewController and a UITableViewDataSource.<br>
><br>
>> I added the braces because it would be really when you add the question mark for an optional value; an alternative for this case would be<br>
>><br>
>> let controller: Optional<UIViewController, UITableViewDatasource><br>
><br>
> This attempts to declare an optional with two generic types, which doesn't work because Optional only has one type parameter. (But other types, like Dictionary, *do* take two type parameters.)<br>
><br>
> Swift does already have a syntax for declaring that a type must conform to two (or more!) protocols:<br>
><br>
> let controller: protocol<UITableViewDataSource, UITableViewDelegate><br>
><br>
> I think this could probably be extended to support one class type as well, perhaps with a new name:<br>
><br>
> let controller: all<UIViewController, UITableViewDataSource><br>
><br>
> --<br>
> Brent Royal-Gordon<br>
> Architechies<br>
><br>
> _______________________________________________<br>
> swift-evolution mailing list<br>
> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></blockquote></div></div></div></blockquote></div><br></div>