<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 class="">(Disclaimer: This might actually just be a slightly disguised subset of the “allow non-type generic parameters” idea, depending on whether that includes stuff like this:</div><div class=""></div><blockquote type="cite" class=""><div class="">var foo = 2</div><div class="">var bar = Vector&lt;foo&gt;()</div></blockquote><div class="">or if it only addresses this:</div><div class=""></div><blockquote type="cite" class=""><div class="">var bar = Vector&lt;2&gt;()</div></blockquote><div class="">)</div><div class=""><br class=""></div>Building on “pure" from:&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/003684.html" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/003684.html</a><div class=""><br class=""></div><div class="">Consider this function:</div><div class=""><blockquote type="cite" class="">func @pure foo&lt;T,U,V&gt;(_: T.Type, _: U.Type) -&gt; V.Type {…}</blockquote></div><div class=""><br class=""></div><div class="">Since @pure prevents foo from accessing global/static variables, since it can only call other @pure functions, and since its only parameters are themselves other types, then the return type of V must solely depend on the *types* T and U (and what can be gotten from T &amp; U using @pure functions). While this is not the same thing as “known at compile time”, it does (I think) guarantee that V can be deduced only using what is known about T and U *at compile time*. If the return value of such a function could used as a “proper” type (i.e., it could be used like “var bar: foo(Int.self, String.self)”, for instance), it wouldn’t so much remove the “types must be known at compile time” restriction, as it would give the programmer a powerful way to tell the compiler *how* to figure out what the type is.</div><div class=""><br class=""></div><div class="">The use case I’m thinking of is admittedly pretty narrow… I &nbsp;personally want this feature to help with a work-around I’m using for Swift not having non-type generic parameters:</div><div class=""></div><blockquote type="cite" class=""><div class="">protocol IVAT { //Integer Value As Type</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>static var integerValue:Int {get}&nbsp;</div><div class="">}</div><div class="">struct _0 : IVAT { static let integerValue = 0 }</div><div class="">struct _1 : IVAT { static let integerValue = 1 }</div><div class="">struct _2 : IVAT { static let integerValue = 2 }</div><div class="">//…etc</div><div class="">&nbsp;</div></blockquote><div class=""><blockquote type="cite" class="">struct Matrix&lt;M:IVAT, N:IVAT&gt; {</blockquote><blockquote type="cite" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>private var&nbsp;backing = [[Double]](count: M.integerValue, repeatedValue: [Double](count: N.integerValue, repeatedValue: 0.0))</blockquote><div class=""><blockquote type="cite" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>subscript(row: Int, col: Int) -&gt; Double {}</blockquote></div><blockquote type="cite" class="">}</blockquote></div><div class=""><br class=""></div><div class="">If we allowed pure functions to return “usable” types, then Matrices could be joined like this:</div><blockquote type="cite" class=""><div class="">func @pure + &lt;T: IVAT, U: IVAT, V: IVAT&gt; (_: T.Type, _: U.Type) -&gt; V.Type {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>switch (T, U) {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case (_0, _0): return _0.self</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case (_0, _1): return _1.self</div></blockquote><blockquote type="cite" class=""><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>…</div></blockquote><blockquote type="cite" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>default: return _0.self<br class=""></blockquote><blockquote type="cite" class=""><div class="">}</div></blockquote><blockquote type="cite" class=""><div class="">// joins two matrices… join([[1,2],[3,4]], [[5],[6]]) would return [[1,2,5],[3,4,6]]&nbsp;</div><div class="">func join &lt;M:IVAT, N1:IVAT, N2:IVAT&gt; (lhs: Matrix&lt;M,N1&gt;, rhs: Matrix&lt;M, N2&gt;) -&gt; Matrix&lt;M, N1.self + N2.self&gt; {…}</div></blockquote><div class=""><br class=""></div><div class="">Again, I realize the use case I’ve presented is pretty narrow (and one that’ll hopefully become a moot point later), but it seems like this would be a *very* expressive way to expand the power of generic types.</div><div class=""><br class=""></div><div class="">Anyway… Yay? Nay? Implementation-wise, my first thought is to embed the REPL in the generic specialization system then use the function in question as its input to extend the generic specialization system, but I don’t know if that’s the right place to handle it, let alone if that’s a feasible idea.</div><div class=""><br class=""></div><div class="">-Dave</div></body></html>