[swift-evolution] [Discussion] Generic protocols

Anton Zhilin antonyzhilin at gmail.com
Tue Dec 6 03:33:24 CST 2016


What makes me worry is if this syntax is really the best one possible:

typealias ConstructibleFrom<V> = ConstructibleFromValue where ValueType == V

I find it strange that such exact line with typealias and where is
required. I was hoping for an expression that lets us specialize a protocol
and use it in-place, like so:

extension MyType : ConstructibleFromValue<ValueType == V>extension
MyType : (ConstructibleFromValue where ValueType == V)

Also I thought that this topic does not really belong to generalized
existentials:

var x: ConstructibleFrom<Float>

I mean, we specify all the types here, so the compiler should just
specialize the protocol and use it as a normal existential. The only thing
that does not allow us to do that now is syntax.
By comparison, the following typealias does require generalized
existentials, because some associatedtypes, including Iterator, are not
specified:

typealias GenericCollection<E> = Collection where Iterator.Index ==
Int, Element == E

It also shows that future generalized-existentials syntax will likely be
exactly the same as the one we choose now for protocol specialization.
So we still should think twice before proceeding. We can implement this
proposal now, but do we want to?
‚Äč
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161206/cc8fa5ce/attachment.html>


More information about the swift-evolution mailing list