<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="">Le 28 janv. 2016 à 19:56, Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 28, 2016, at 4:04 PM, Haravikk <<a href="mailto:e-mail@haravikk.me" class="">e-mail@haravikk.me</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=""><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On 28 Jan 2016, at 22:37, Joe Groff 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=""><br class=""><blockquote type="cite" class="">On Jan 28, 2016, at 2:36 PM, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>> wrote:<br class=""><br class="">I like this idea, but the syntax seems dangerously close to a call site for "func *(lhs: Int, rhs: Any.Type)" (which is obviously ill-advised, but it is allowed).<br class=""><br class="">Maybe we could take advantage of something which would be very invalid under the current grammar, namely (n T) rather than (n * T):<br class=""><br class=""> let values: (4 Int) = (1, 2, 3, 4)<br class=""></blockquote><br class="">Sure, or we could lift (4 x Int) from LLVM IR's syntax.</div></blockquote><br class=""></div><div class="">How about:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span><font face="Monaco" class="">let values:Int[4] = (1,2,3,4)</font></div><div class=""><br class=""></div><div class="">While it looks a bit like a subscript, it doesn’t make sense in a type declaration at present, so could be a good way to define restrictions of this type (we could even extend it to collections later). If the similarity is too close then:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span><font face="Monaco" class="">let values:(Int[4]) = (1,2,3,4)</font></div><div class=""><br class=""></div><div class="">Could work too? Just some alternatives anyway, as I like the idea.</div></div></div></blockquote></div><br class=""><div class="">This kind of syntax doesn't compose well with other type productions. If you parse Int[N][M] naively as (Int[N])[M], then you end up with an array of M (array of N (Int)), which ends up subscripting in the opposite order, array[0..<M][0..<N]. C works around this by flipping the order of multiple array indices in a type declaration, so int [n][m] is really (int [m]) [n], but this doesn't work well for Swift, which has other postfix type productions—how would Int[N]?[M] parse? Choosing a prefix notation for fixed-sized array bounds is better IMO to avoid these pitfalls.</div></div></div></blockquote><br class=""></div><div><div>Hmm… Two dimensions tuples...</div><div>let matrix: (2 (4 Int)) = ( (1,2,3,4), (5,6,7,8) )</div><div>print(matrix.0.0, matrix.1.3) // display 1 and 8</div><div>// Output based on let matrix = ((1,2,3,4), (5,6,7,8))</div><div class=""><br class=""></div><div class="">The type is easier to read with LLVM IR syntax mentioned by Joe</div><div class=""><div>let matrix: (2 x (4 x Int)) = ( (1,2,3,4), (5,6,7,8) )</div></div><div class=""><br class=""></div><div class="">A one dimensional tuple is supposed to be contiguous, but does the same behaviour apply to tuples of tuples?</div><div class=""><br class=""></div><div class="">Dany</div><div class=""><br class=""></div></div><br class=""></body></html>