[swift-evolution] [Pitch] Require Any for existentials
Anton Zhilin
antonyzhilin at gmail.com
Tue Aug 23 15:49:47 CDT 2016
I haven't yet prepared a formal proposal, but the idea should be understood
by pretty much everyone. This topic has been discussed, but deferred to
"post-Swift3". I think the time for it has come.
Basically, the proposal is to make protocols non-types. To use protocol as
an existential type, it must be wrapped in Any:
protocol ExampleProtocol {
func foo() -> Int
func bar() -> String
}
func f<T: ExampleProtocol>() // OK
func f(x: ExampleProtocol) // error: ExampleProtocol is not a type
func f(x: Any<ExampleProtocol>) // OK
This will syntactically separate existential types from protocols
themselves and generic constraints.
The proposal does not allow for much variativity, and it looks like the
proposal can be easily created and submitted.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160823/2ec792e2/attachment.html>
More information about the swift-evolution
mailing list