<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 14, 2016, at 10:27 AM, Milos Rankovic via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; 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="">In Swift, we cannot compile:<div class=""><font face="Menlo" size="2" class=""><br class=""></font></div><div class=""><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="" size="2"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);">_</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;= [[],&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">1</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">2</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">3</span><span class="" style="font-variant-ligatures: no-common-ligatures;">], [[</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">4</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">5</span><span class="" style="font-variant-ligatures: no-common-ligatures;">], [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">6</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">7</span><span class="" style="font-variant-ligatures: no-common-ligatures;">], [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">8</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">9</span><span class="" style="font-variant-ligatures: no-common-ligatures;">]]]</span></font></div></div></div><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" size="2" class=""><br class=""></font></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;">The reason for the compile-time error is that we are not in fact creating an array, but a tree – a more general structure of which arrays are only a special case. Given the well-deserved and growing reputation of Swift, one would hope that in this instance the compiler would be able to default to something like a:</span></div></div></div></blockquote><div><br class=""></div><div>Actually this error can be simplified to&nbsp;</div><div><br class=""></div><div>_ = []</div><div><br class=""></div><div>As the compiler says, the expression is ambiguous. Without an element type, the array literal cannot be used to create an array.</div><div><br class=""></div><div>On the other hand:</div><div><br class=""></div><div>_ = [[1]]</div></div><div><br class=""></div><div>is fine - &nbsp;the system assumes the literal your literal was defining an array of int, so the outer type is Array&lt;Array&lt;Int&gt;&gt;</div><div><br class=""></div><div><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;">For this to work in the playground, however, we must manually lift the values into the world of trees first. And to make that chore in turn easier on the eye we can introduce a:</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="Menlo" size="2" class=""><br class=""></font></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="Menlo" size="2" class=""><div class="" style="margin: 0px; line-height: normal; color: rgb(203, 203, 203);"><font class=""><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);">prefix</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);">operator</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;◊ {}&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">// looks a bit like a leaf (us/uk kbd:&nbsp;</span><span class="" style="line-height: normal; font-variant-ligatures: no-common-ligatures;"><b class="">⎇⇧</b></span><span class="" style="font-variant-ligatures: no-common-ligatures;">V)</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font class=""><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);">prefix</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);">func</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;◊ &lt;T&gt; (leaf:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);">T</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) -&gt;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);">Tree</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&lt;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);">T</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&gt; {&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);">return</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);">Leaf</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(leaf) }</span></font></div><div class="" style="margin: 0px; line-height: normal; min-height: 17px;"><font class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal;"><font class=""><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;tree:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);">Tree</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&lt;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&gt; = [[],&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);">◊</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">1</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);">◊</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">2</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);">◊</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">3</span><span class="" style="font-variant-ligatures: no-common-ligatures;">], [[</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);">◊</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">4</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);">◊</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">5</span><span class="" style="font-variant-ligatures: no-common-ligatures;">], [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);">◊</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">6</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);">◊</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">7</span><span class="" style="font-variant-ligatures: no-common-ligatures;">], [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);">◊</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">8</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(145, 84, 15);">◊</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">9</span><span class="" style="font-variant-ligatures: no-common-ligatures;">]]]</span></font></div></font></span></div></div></blockquote><div><br class=""></div>Yes, because there is no way to have one type be cast implicitly into another type except for the cases the compiler supports via Optional or the various LiteralConvertible protocols/initializers.</div><div><br class=""></div><div>So as other point out, if you actually defined a Integer-only tree, you could define that a .leaf was created from integer literals. Then this works without your wrapping operator.</div><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=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="Menlo" size="2" class=""><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div></font></span></div><div class="">The point here is that if adding such a fundamental type to the Standard Library would not be a priority at present, it is not the end of the world since we can easily enough write it ourselves… What we cannot do ourselves, however, is to get rid of the need for that operator in the common scenario of initialising with literal values. For this we need a literal-convertible protocol requiring&nbsp;<b class="">two</b>&nbsp;initialisers:</div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="Menlo" size="2" class=""><br class=""></font></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" size="2" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="color: rgb(73, 162, 210);" class="">TreeLiteralConvertible</span>&nbsp;{</div><div style="margin: 0px; line-height: normal; color: rgb(200, 172, 229);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures" class="">associatedtype</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> LeafValue</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(literal: </span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.LeafValue...)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(literal: </span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Self</span><span style="font-variant-ligatures: no-common-ligatures" class="">...)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></font></div></div></div></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;">Then we could simply:</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="Menlo" size="2" class=""><br class=""></font></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class="" size="2"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;tree:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);">Tree</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&lt;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(73, 162, 210);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&gt; = [[],&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">1</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">2</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">3</span><span class="" style="font-variant-ligatures: no-common-ligatures;">], [[</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">4</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">5</span><span class="" style="font-variant-ligatures: no-common-ligatures;">], [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">6</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">7</span><span class="" style="font-variant-ligatures: no-common-ligatures;">], [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">8</span><span class="" style="font-variant-ligatures: no-common-ligatures;">,&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(255, 38, 0);">9</span><span class="" style="font-variant-ligatures: no-common-ligatures;">]]]</span></font></div></div></span></div></div></blockquote><div><br class=""></div>If my tree is of Pear objects, there is no “Pear” literal in the language. So I don’t think you are asking for tree literals. I suspect you are asking for implicit type coercion, which if present could possibly replace some of the existing LiteralConvertible protocols..</div><div><br class=""></div><div>-DW</div><br class=""></body></html>