[swift-evolution] Proposal: An Either Type in the STL
Thorsten Seitz
tseitz42 at icloud.com
Sat Dec 12 12:48:33 CST 2015
> Am 11.12.2015 um 03:14 schrieb John McCall via swift-evolution <swift-evolution at swift.org>:
>
> Right, sorry; I’ve gotten too used to the C++ sense. I mean types which contain free uses of the generic parameters of the context, which therefore appear to be opaque there. It’s a problem for union typing because the intersection of any opaque types with the other concrete types in a union is not necessarily empty. It’s not an unsolvable problem, of course.
Do you mean something along these lines (taken from Ceylon)?
interface Set<These> {
shared formal Set<These | Those> union<Those>(Set<Those> set);
shared formal Set<These & Those> intersection<Those>(Set<Those> set);
}
Set<Foo> setOfFoo = ... ;
Set<Bar> setOfBar = ... ;
Set<Foo | Bar> setUnion = setOfFoo.union(setOfBar); // each element conforms to Foo or Bar
Set<Foo & Bar> setIntersection = setOfFoo.intersection(setOfBar); // each element conforms to Foo and Bar
Types like (Int | Int) reduce to Int, of course, etc.
-Thorsten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151212/01f0b9f8/attachment.html>
More information about the swift-evolution
mailing list