<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="">Hi John,<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 14 Apr 2016, at 21:09, John McCall <<a href="mailto:rjmccall@apple.com" class="">rjmccall@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: -webkit-standard; font-size: inherit; 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-stroke-width: 0px; float: none; display: inline !important;" class="">I mean, you could just make your Tree type implement all the individual literal-convertible protocols.</span></div></blockquote></div><br class=""></div><div class="">It does sound like something like that should be doable, but it isn’t. The literal-convertible protocols only require one initialiser, but you need two: one that lifts leaf values to Self and the other that actually takes Self elements (it is this last one that provides for recursion). In other words, we’d need to overload our conformance:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; color: rgb(73, 162, 210);" class=""><font face="Menlo" class=""><span style="font-size: small; font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);" class="">extension</span><span style="font-size: small; font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> </span><span style="font-size: small; font-variant-ligatures: no-common-ligatures;" class="">Tree</span><span style="font-size: small; font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> : </span><span style="font-size: small; font-variant-ligatures: no-common-ligatures;" class="">ArrayLiteralConvertible</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""><font size="2" class=""> { </font></span></font><span style="color: rgb(203, 203, 203);" class=""><font face="Menlo" size="2" class="">// error: does not conform!</font></span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" size="2" 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="">(arrayLiteral elements: </span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Tree</span><span style="font-variant-ligatures: no-common-ligatures" class="">...) {</span></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" size="2" 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="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = .</span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Branches</span><span style="font-variant-ligatures: no-common-ligatures" class="">(elements)</span></font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font face="Menlo" size="2" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" size="2" 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="">(arrayLiteral elements: </span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Value</span><span style="font-variant-ligatures: no-common-ligatures" class="">...) {</span></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" size="2" 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="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> elements.</span><span style="font-variant-ligatures: no-common-ligatures; color: #8f793a" class="">count</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == </span><span style="font-variant-ligatures: no-common-ligatures; color: #ff2600" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = .</span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Leaf</span><span style="font-variant-ligatures: no-common-ligatures" class="">(elements[</span><span style="font-variant-ligatures: no-common-ligatures; color: #ff2600" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">]) }</span></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" size="2" 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="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = .</span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Branches</span><span style="font-variant-ligatures: no-common-ligatures" class="">(elements.</span><span style="font-variant-ligatures: no-common-ligatures; color: #91540f" class="">map</span><span style="font-variant-ligatures: no-common-ligatures" class="">{ .</span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">Leaf</span><span style="font-variant-ligatures: no-common-ligatures" class="">($0) }) }</span></font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font face="Menlo" size="2" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font face="Menlo" size="2" class="">}</font></span></div></div><div class=""><br class=""></div><div class="">But you can only conform in one or the other way, but not both! Therefore, for trees, we need something like:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" size="2" 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=""> <span style="color: rgb(73, 162, 210);" class="">TreeLiteralConvertible</span> {</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(200, 172, 229);" class=""><font face="Menlo" size="2" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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; color: #000000" class=""> LeafValue</span></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" size="2" 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></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" size="2" 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></font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font face="Menlo" size="2" class="">}</font></span></div></div><div class=""><br class=""></div><div class="">milos</div></body></html>