[swift-evolution] [Discussion] Generic protocols

Daniel Leping daniel at crossroadlabs.xyz
Tue Dec 6 08:39:02 CST 2016


Does not this make associatedtype redundant additional complexity?

On Tue, 6 Dec 2016 at 16:35 Martin Waitz <tali at admingilde.org> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161206/47a5b35f/attachment.html>


More information about the swift-evolution mailing list