<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><blockquote type="cite" class=""><div class="">On 15 Apr 2016, at 19:54, Haravikk <<a href="mailto:swift-evolution@haravikk.me" class="">swift-evolution@haravikk.me</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="">While the original post is an interesting way to define this structure, I think a specialised type is required to really capture this usefully.</span></div></blockquote></div><br class=""><div class="">Sure. I never meant it as a replacement. It was a response to someone’s challenge whether one could express a piece of JSON data as a literal using the two example tree enums. The two protocols I’m proposing, however, could be implemented by many different kind of tree types, some of which could just as well have properties that fit JSON perfectly. It would then be a joy instantiating short JSON snippets as literals.</div><div class=""><br class=""></div><div class="">Still, as John anticipated, I could get this to compile too (keeping in mind that the lift operator ◊ would disappear if we get the two proposed protocols):</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; color: rgb(73, 162, 210);" class=""><font size="2" face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(200, 172, 229);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> johnny: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">DictionaryTree</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""><</span><span style="font-variant-ligatures: no-common-ligatures;" class="">String</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">, </span><span style="font-variant-ligatures: no-common-ligatures;" class="">JSONValue</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">> =</span></font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font size="2" face="Menlo" class="">[</font></span></div><div style="margin: 0px; line-height: normal; color: rgb(100, 150, 29);" class=""><font size="2" face="Menlo" 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="">"children"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #91540f" class="">◊</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">[</span><span style="font-variant-ligatures: no-common-ligatures" class="">"George"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures" class="">"Ann"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures" class="">"Percy"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">],</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(100, 150, 29);" class=""><font size="2" face="Menlo" 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="">"phoneNumbers"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #91540f" class="">◊</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">[</span></font></div><div style="margin: 0px; line-height: normal;" class=""><font size="2" face="Menlo" 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: #91540f" class="">◊</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(100, 150, 29);" class=""><font size="2" face="Menlo" 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="">"type"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #91540f" class="">◊</span><span style="font-variant-ligatures: no-common-ligatures" class="">"home"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">,</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(100, 150, 29);" class=""><font size="2" face="Menlo" 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="">"number"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #91540f" class="">◊</span><span style="font-variant-ligatures: no-common-ligatures" class="">"212 555-1234"</span></font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font size="2" face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>],</font></span></div><div style="margin: 0px; line-height: normal;" class=""><font size="2" face="Menlo" 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: #91540f" class="">◊</span><span style="font-variant-ligatures: no-common-ligatures" class="">[</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(100, 150, 29);" class=""><font size="2" face="Menlo" 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="">"type"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #91540f" class="">◊</span><span style="font-variant-ligatures: no-common-ligatures" class="">"office"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">,</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(100, 150, 29);" class=""><font size="2" face="Menlo" 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="">"number"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #91540f" class="">◊</span><span style="font-variant-ligatures: no-common-ligatures" class="">"646 555-4567"</span></font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font size="2" face="Menlo" 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 size="2" face="Menlo" 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 size="2" face="Menlo" class="">]</font></span></div></div><div class=""><br class=""></div><div class="">… where:</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="">enum</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> JSONValue {</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="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Text(</span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">String</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="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Array([</span><span style="font-variant-ligatures: no-common-ligatures; color: #49a2d2" class="">JSONValue</span><span style="font-variant-ligatures: no-common-ligatures" class="">])</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(73, 162, 210);" 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; color: #c8ace5" class="">indirect</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c8ace5" class="">case</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> Object(</span><span style="font-variant-ligatures: no-common-ligatures" class="">DictionaryTree</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><</span><span style="font-variant-ligatures: no-common-ligatures" class="">String</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, </span><span style="font-variant-ligatures: no-common-ligatures" class="">JSONValue</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" 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><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>