[swift-evolution] [Idea] Generic associated types

Daniel Leping daniel at crossroadlabs.xyz
Mon Mar 20 19:38:48 CDT 2017


Totally +1 here.

On Mon, Mar 20, 2017 at 11:12 PM, Douglas Gregor via swift-evolution <
swift-evolution at swift.org> wrote:

>
> On Mar 11, 2017, at 9:49 PM, Karl Wagner <razielim at gmail.com> wrote:
>
> I have a model like this:
>
> protocol Promise {
>     associatedtype Result
> }
>
> protocol Scanner {
>     associatedtype ScanPromise: Promise
>
>     func promiseScan<T>(from: Offset, until: (Offset, Item) -> T?) ->
> ScanPromise // where Result == T?
> }
>
>
> The thing that I’m trying to express is: whichever type implements the
> associated type ‘ScanPromise’ must be generic, and that parameter must be
> its result (i.e. something it got as a result of calling the “until”
> closure).
>
> Even with SE-0142, this kind of constraint would not be possible. What I
> would like to write is something like this:
>
> protocol Promise {
>     associatedtype Result
> }
>
> protocol Scanner {
>     associatedtype ScanPromise<T>: Promise // now generic. [SE-0142]:
> where Result == T
>
>     func promiseScan<T>(from: Offset, until: (Offset, Item) -> T?) ->
> ScanPromise<T>
> }
>
> Thoughts?
>
>
> Some of us who work on the Swift compiler have talked about this extension
> to the model before, and we *think* it dodges some of the concerns about
> introducing more-general higher-rank types in Swift while enabling
> reasonable use cases like the one you provide. It seems like a reasonable
> direction.
>
> Way out of scope for Swift 4 at this point, of course ;)
>
> - Doug
>
>
>
> _______________________________________________
> 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/20170321/595f7096/attachment.html>


More information about the swift-evolution mailing list