[swift-evolution] protocol can only be used as a generic constraint because it has Self or associated type requirements

Tal Atlas me at tal.by
Mon Dec 14 07:45:06 CST 2015


This is the error that gets in my way the most when trying to do protocol
oriented programming. It can be super frustrating. That lead me to make a
proposal a few weeks back for having generic protocols.

In that proposal some swift core people expressed that they were keenly
aware of said pain. And while they didn't deliver details in time or
implementation they expressed that there were efforts ongoing to solve it.

On Sun, Dec 13, 2015 at 6:55 PM Marc Knaup via swift-evolution <
swift-evolution at swift.org> wrote:

> Hey guys,
>
> I'm looking at Swift 3.0's goal to improve generics.
>
> Is there any info yet if and how we will be able to refer to instances of
> protocols that have associated types?
> What is the difficulty in supporting this?
>
> Simple examples:
> var list = [Hashable]()
> var hashable: Hashable = 2
>
> Right now all we get is
>
>> protocol 'Hashable' can only be used as a generic constraint because it
>> has Self or associated type requirements
>
>
> Thanks,
>   Marc
>
> _______________________________________________
> 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/20151214/180c2d68/attachment.html>


More information about the swift-evolution mailing list