[swift-evolution] Enhanced existential types proposal discussion
Adrian Zubarev
adrian.zubarev at devandartist.com
Thu May 26 15:39:39 CDT 2016
I alway enjoy hearing your ideas.
This is quite interesting. It's basically a way to define an ad-hoc interface that a type doesn't need to explicitly declare it conforms to. I know Golang works similarly; if a Go type implements all the requirements of an interface it conforms automatically.
There are positives and negatives to allowing this sort of ad-hoc interface.
Agree. It would definitely make the language "feel" a bit more fluid. But it doesn't add any expressive power and could have undesirable consequences.
This would make for a good standalone proposal -- both because it's complex enough to deserve its own discussion, and because if the community is interested someone would have to work through all the implications in order to put together a proposal. It would be quite a big change.
I don't see how this is different from a protocol other than the lack of requirement to declare conformance explicitly. The need to explicitly declare conformance is a design decision that I believe the core team feels pretty strongly about.
That said, it hasn't been debated by the community yet so if someone feels strongly about dropping explicit conformance declarations it might be worth pitching the idea, if for not other reason than to have a discussion about it on the lost.
I don’t see any desire to follow Go’s path here and drop explicit conformance in any way.
Basically such `existential` mechanism could express more than `Any<…>` could. That said I do feel that this "could“ have some potential to exist alongside `Any<…>`.
From my understanding of this whole existential type thing is that it can be used both ways, explicitly and implicitly. As said before we only discussed the explicit existential types.
Just another pseudo example:
```swift
// this could also replace typealiases for (generic) existentials
existential CrazyView {
// we could introduce a way for constraints which could have a nice looking syntax
// break `Any<…>` nesting and long very long composition lines of `Any<…>`
constraint Any<UIScrollView, Any<UITableView, Any<UIView, ProtocolA>>>
constraint ProtocolA.AssociatedType == Int
func crazyFunction()
}
existential AnyCollection<T> {
constraint Collection
constraint Collection.Element == T
}
```
But I don’t want to go any further if there is no need (yet).
--
Adrian Zubarev
Sent with Airmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160526/d0caa708/attachment.html>
More information about the swift-evolution
mailing list