<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 Apr 4, 2016, at 3:07 PM, Haravikk 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">One of the things that threw me when starting with Swift was the inability to use many protocols as types, e.g- being unable to declare: [SequenceType], instead having to do: [AnySequence]<div class=""><br class=""></div><div class="">And I guess it got me wondering; why can’t we just have these be auto-generated and used where we would expect a protocol to fit? Writing type-erased wrappers currently involves a lot of boilerplate, especially for a type with a lot of methods and/or properties, so automating this would be very useful.</div><div class=""><br class=""></div><div class="">For me there are two good options:</div><div class=""><br class=""></div><div class=""><b class="">Autogenerate for All Types</b>: As it says; every protocol would have an identically named type-erasure (with the same visibility etc.) that Swift would just swap in where appropriate. For example:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>protocol Foo { … }</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let myArray:[Foo]<span class="Apple-tab-span" style="white-space:pre">        </span>// Array of type-erased wrappers of Foo</font></div></div></div></blockquote><div><br class=""></div><div>The only reason you can’t use [Foo] is due to associated type or Self requirements so what type is Foo’s associated type(s) here? </div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><br class=""></div></div><div class=""><br class=""></div><div class="">I’m particularly curious about other features in discussion or that are upcoming that may affect this, as I’m sure I’ll have missed some. Anything that might render this obsolete (or less necessary)? Also whether anyone thinks it could be a bad idea to essentially hide the type-erasure.</div></div><br class=""></blockquote><br class=""></div><div>The Completing Generics manifesto discusses this in the context of Existential types. If that were supported, then the compiler would just treat the associated types as Any. It also discusses allowing you to create types ala protocol<SequenceType where Element == String></div><div><br class=""></div><div><br class=""></div><div>Russ</div><br class=""></body></html>