<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 Aug 30, 2017, at 8:01 AM, Robert Widmann <<a href="mailto:devteam.codafi@gmail.com" class="">devteam.codafi@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><br class="Apple-interchange-newline">On Aug 29, 2017, at 5:22 PM, David Sweeris via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Aug 29, 2017, at 1:49 PM, Slava Pestov <<a href="mailto:spestov@apple.com" class="">spestov@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On Aug 29, 2017, at 11:03 AM, David Sweeris via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:<br class=""><br class="">Hi everyone! I'm trying to implement literal values as generic types.<br class=""></blockquote><br class="">Can you briefly explain what you mean by this?<br class=""><br class="">Are you referring to let-polymorphism, like<br class=""><br class="">let fn = { $0 }<br class="">let f1: (Int) -> Int = fn<br class="">let f2: (Float) -> Float = fn<br class=""></div></div></blockquote></div><br class=""><div class="">No, I mean so that a vector's or matrix's dimensions can be part of its type (strawman syntax and protocol name, but this is pretty much what I'll be trying to support, at least at first):</div><div class=""><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Fantasque Sans Mono'; color: rgb(127, 135, 207); background-color: rgb(0, 57, 70);"><span class="" style="color: rgb(222, 81, 148);">struct</span><span class="" style="color: rgb(164, 176, 177);"><span class="Apple-converted-space"> </span>Vector<T:<span class="Apple-converted-space"> </span></span>ExpressibleByIntegerLiteral<span class="" style="color: rgb(164, 176, 177);">, L:<span class="Apple-converted-space"> </span></span>IntegerLiteralExpr<span class="" style="color: rgb(164, 176, 177);">> {</span></div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Fantasque Sans Mono'; color: rgb(164, 176, 177); background-color: rgb(0, 57, 70);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(222, 81, 148);">var</span><span class="Apple-converted-space"> </span>elements: [<span class="" style="color: rgb(127, 135, 207);">T</span>]</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Fantasque Sans Mono'; color: rgb(164, 176, 177); background-color: rgb(0, 57, 70);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(222, 81, 148);">init</span>() {</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Fantasque Sans Mono'; background-color: rgb(0, 57, 70);"><span class="" style="color: rgb(164, 176, 177);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(47, 175, 169);">elements</span><span class="Apple-converted-space"> </span>= [<span class="" style="color: rgb(127, 135, 207);">T</span>](repeating:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(229, 73, 61);">0</span>, count:<span class="Apple-converted-space"> </span></span><font color="#7f87cf" class="">L</font><font color="#a4b0b1" class="">)</font></div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Fantasque Sans Mono'; color: rgb(164, 176, 177); background-color: rgb(0, 57, 70);"> }</div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Fantasque Sans Mono'; color: rgb(164, 176, 177); background-color: rgb(0, 57, 70);">}</div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(0, 57, 70); min-height: 14px;"><br class=""></div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Fantasque Sans Mono'; color: rgb(164, 176, 177); background-color: rgb(0, 57, 70);"><span class="" style="color: rgb(222, 81, 148);">let</span><span class="Apple-converted-space"> </span>vect =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(127, 135, 207);">Vector</span><span class="" style="text-decoration: underline;"><</span><span class="" style="color: rgb(127, 135, 207);">Int</span>,<span class="Apple-converted-space"> </span><span class="" style="text-decoration: underline; color: rgb(229, 73, 61);">5</span>>()</div></div><div class=""><br class=""></div><div class="">And, once that's working, I'm going to add support simple "type functions":</div><div class=""><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: 'Fantasque Sans Mono'; color: rgb(164, 176, 177); background-color: rgb(0, 57, 70);"><span class="" style="color: rgb(222, 81, 148);">func</span><span class="Apple-converted-space"> </span>join <T, L1, L2> (<span class="" style="color: rgb(222, 81, 148);">_</span><span class="Apple-converted-space"> </span>lhs:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(127, 135, 207);">Vector</span><<span class="" style="color: rgb(127, 135, 207);">T</span>,<span class="Apple-converted-space"> </span><span class="" style="color: rgb(127, 135, 207);">L1</span>>,<span class="Apple-converted-space"> </span><span class="" style="color: rgb(222, 81, 148);">_</span><span class="Apple-converted-space"> </span>rhs:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(127, 135, 207);">Vector</span><<span class="" style="color: rgb(127, 135, 207);">T</span>,<span class="Apple-converted-space"> </span><span class="" style="color: rgb(127, 135, 207);">L2</span>>) -> <span class="" style="color: rgb(127, 135, 207);">Vector</span><<span class="" style="color: rgb(127, 135, 207);">T</span>, <span class="" style="color: rgb(127, 135, 207);">L1</span> + <span class="" style="color: rgb(127, 135, 207);">L2</span> > {...}</div></div><div class="">I think restricting the supported "type functions" to expressions that could be evaluated by the compiler's "constant folding" code would be a reasonable place to start, until we figure out what we want to do about "pure"/"constexpr" stuff... even just "+" for numeric and string literals, and "-" for numeric literals, seems like a reasonable starting goal, and I<span class="Apple-converted-space"> </span><i class="">think</i> that'd be simple enough to implement (famous last words, right?)... It's all academic until I get the simple cases working first, though.</div></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Constant folding occurs too late in the compilation process for you to take advantage of it in the solver. You’ll need to write your own evaluator and teach CSSimplify to invoke it during the type matching process. I would start by adding a new kind of Type and TypeRepr that hold SequenceExpr nodes and a CanType that holds an APSInt representing the result of evaluating the expression.</div></div></blockquote><br class=""></div><div>Thanks! I'll keep this in mind when it's time to implement it.</div><br class=""><div class="">- Dave Sweeris</div></body></html>