<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=""><div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">I'm starting to think my original motivation might’ve had something to do with normally needing storage for both some property <i class="">and</i> a T, but not needing (local) storage for said property if T conformed to a protocol which itself already required conforming types to have that property? Or maybe as a way to have the “bottom” variable in a hierarchy of wrapper types to break the “reference cycle” for some property? (Come to think of it, those could be the same thing)</div><div class=""><br class=""></div><div class="">That was (and is) an odd project... Anyway, it's been a while since I've thought about it. I'll try to find time today to poke through some old code and see if still have a copy of what I’d gotten stuck on.</div><div class=""><br class=""></div><div class="">And thanks for those links :-)</div></div></div></blockquote></div></div></div></blockquote></div><br class=""><div class="">It sounds like what you want is similar to C++ template specialization (also something I’ve been asking for). Another slightly different form you can imagine it taking is:</div><div class=""><br class=""></div><div class="">class Array {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>associatedtype StorageType:Storage</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>subscript(index:[Int]) -> StorageType.ElementType { /* … */ }</div><div class="">}</div><div class=""><br class=""></div><div class="">extension Array where StorageType:FloatStorage {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// define specific variables for this specialization</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// and define behavior for subscript</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Another example might be (if ints were allowed as generic parameters):</div><div class=""><br class=""></div><div class="">struct Factorial<N:Int> {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var value { return N * Factorial <N-1>.value }</div><div class="">}</div><div class=""><br class=""></div><div class="">struct Factorial<N:Int> where N == 1 {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var value { return 1 }</div><div class="">}</div><div class=""><br class=""></div><div class="">let value = Factorial<10>.value</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">The first example can in theory be done using runtime information (though as stated in my previous posts, I still can’t get it to work correctly in Swift). The second clearly needs to be done at compile time and could potentially benefit from the `constexpr` discussed in the `pure` function thread. A slightly different formulation could be:</div><div class=""><br class=""></div><div class="">constexpr factorial<N:Int>() { return N*factorial<N-1>() }</div><div class="">constexpr factorial<N:Int>() where N == 1 { return 1 }</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Right now generics in Swift feel closer to Java’s generics than c++ templates. I think these types of constructs are extremely useful to a language and would disagree with anyone who says they aren’t needed (e.g. look at Boost and Eigen). However, I can also appreciate that adding these features to a language probably should be done with lots of care and thought.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">A</div></body></html>