> On 15 Apr 2016, at 19:54, Haravikk <[email protected]> wrote:
> 
> While the original post is an interesting way to define this structure, I 
> think a specialised type is required to really capture this usefully.

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.

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):

let johnny: DictionaryTree<String, JSONValue> =
[
        "children": ◊["George", "Ann", "Percy"],
        "phoneNumbers": ◊[
                ◊[
                        "type": ◊"home",
                        "number": ◊"212 555-1234"
                ],
                ◊[
                        "type": ◊"office",
                        "number": ◊"646 555-4567"
                ],
        ]
]

… where:

enum JSONValue {
        case Text(String)
        case Array([JSONValue])
        indirect case Object(DictionaryTree<String, JSONValue>)
}

milos










_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to