[swift-evolution] [Discussion] Generic protocols
Martin Waitz
tali at admingilde.org
Tue Dec 6 08:35:22 CST 2016
Am 2016-12-06 15:01, schrieb Daniel Leping via swift-evolution:
>
> 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.
we should be careful not to mix up associated types with actual generic
type parameters.
When we introduce type parameters for protocols, they should be written
within angle brackets.
Requirements for associated types should just stay after `where`.
>> 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.
Why?
It introduces a new generic type which is equivalent to some protocol
with additional requirements,
where the requirement on the associated type is parameterized.
Of course we should also allow to directly write parameterized
protocols:
protocol ConstructibleFrom<V> {
[...]
}
which can then be used with the type parameter:
struct Stuff: ConstructibleFrom<Things> {}
When we consider type parameters to be part of the protocol name,
then we can also support conformance to multple protocols which only
differ in the type parameter.
--
Martin
More information about the swift-evolution
mailing list