[swift-evolution] [Discussion] Generic protocols

Daniel Leping daniel at crossroadlabs.xyz
Tue Dec 6 08:01:25 CST 2016


ConstructibleFromValue<ValueType == V>

Sounds way better to me than the second option considering we can't do just

ConstructibleFromValue<V>

Because of lack of order of associated types. So IMO either we introduce
order or we use == syntax. Maybe somebody has more ideas of a better syntax?

On Tue, 6 Dec 2016 at 11:33 Anton Zhilin via swift-evolution <
swift-evolution at swift.org> wrote:

> 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?
> ‚Äč
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161206/14d5963d/attachment.html>


More information about the swift-evolution mailing list