<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 17, 2016, at 6:37 PM, Jens Persson via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Has there been any discussions about the possibility of having generic associatedtypes?<div class=""><br class=""></div><div class="">I (naively) think that it would open up a lot of possibilities.</div><div class="">Because if, for example, we could do this:</div><div class=""><br class=""></div><div class="">protocol CountType {</div><div class=""> associatedtype Storage<E></div><div class=""> ...</div><div class="">}</div><div class=""><br class=""></div><div class="">Then we could do this:</div><div class=""><br class=""></div><div class="">struct Count1 : CountType {</div><div class=""> typealias Storage<E> = (E)</div><div class=""> ...</div><div class="">}</div><div class="">struct Count2 : CountType {</div><div class=""> typealias Storage<E> = (E, E)</div><div class=""> ...</div><div class="">}</div><div class="">struct Count3 : CountType {</div><div class=""> typealias Storage<E> = (E, E, E)</div><div class=""> ...</div><div class="">}</div><div class="">...</div><div class="">protocol StaticArrayType {</div><div class=""> associatedtype Count: CountType</div><div class=""> associatedtype Element</div><div class=""> ...</div><div class="">}</div><div class="">struct StaticArray<C: CountType, Element> : StaticArrayType {</div><div class=""> typealias Count = C</div><div class=""> var storage: C.Storage<Element></div><div class=""> ...</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">Would adding support for generic associatedtypes be possible? Are there any plans for it?</div></div></div></div></blockquote><div><br class=""></div><div><div>Possible, yes, plans, no.</div><div><br class=""></div><div>Generic associated types go part and parcel with higher-kinded quantification and higher-kinded types, the implementation challenges of which have been discussed thoroughly on this list and elsewhere. Is there a particular flavor you had in mind?</div><div><br class=""></div><div>One major problem is that presumably you’d want to constrain such a generic associatedtype and then we’d have to have some kind of type-level-yet-runtime-relevant apply of a generic witness table to another potentially generic witness. It’s not clear what that kind of thing would look like, or how far it would have to be taken to get the kind of support you would expect from a basic implementation higher associatedtypes. Implementations in languages like Haskell tend to also be horrendously inefficient - I believe Edward Kmett calls is the “Mother May I” effect of forcing a witness table to indirect through multiple layers of the witness because inlining necessarily fails for the majority of these things in the MTL.</div><div><br class=""></div><div>tl;dr Basic examples like the ones you cite hide the kinds of tremendously <strike class="">evil</strike> fun things you can do once you have these kinds of features. </div></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">(</div><div class="">I tried searching for it but I found only this:</div><div class=""><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160411/015089.html" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160411/015089.html</a><br class=""></div><div class="">)</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">/Jens</div><div class=""><br class=""></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>