[swift-evolution] TreeLiteralConvertible

John McCall rjmccall at apple.com
Fri Apr 15 10:48:13 CDT 2016

> On Apr 15, 2016, at 1:29 AM, Milos Rankovic <milos at milos-and-slavica.net> wrote:
>> On 15 Apr 2016, at 03:22, John McCall <rjmccall at apple.com <mailto:rjmccall at apple.com>> wrote:

>> Your JSON literal example is already pretty well modeled by simply making a JSONValue type that conforms to all the literal protocols.  It is completely unclear why you would even want to model this with some generic Tree structure. 
> Because JSON has the structure of a tree.  A dictionary of the type `[String:AnyObject]` does not express that structure even if at run-time it turns out that some of those any-objects are themselves dictionaries. `Tree<String, JSONValue>`, in contrast, precisely expresses the structure of JSON objects.

No, it's actually a very strange way to model it.  The JSONValue type needs to be able to embed both JSON arrays and JSON objects, so if you represent a JSON object as a DictionaryTree<String, JSONValue>, you'll end up with two different ways to represent { "x" : { "y" : 1 } }.  It's much better to use the "flat" representation of Dictionary<String, JSONValue> and allow the JSONValue enum's natural recursiveness to express nested objects.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160415/2525776a/attachment.html>

More information about the swift-evolution mailing list