Hi John,

> On 14 Apr 2016, at 21:09, John McCall <[email protected]> wrote:
> 
> I mean, you could just make your Tree type implement all the individual 
> literal-convertible protocols.

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:

extension Tree : ArrayLiteralConvertible { // error: does not conform!
        init(arrayLiteral elements: Tree...) {
                self = .Branches(elements)
        }
        init(arrayLiteral elements: Value...) {
                if elements.count == 1 { self = .Leaf(elements[0]) }
                else { self = .Branches(elements.map{ .Leaf($0) }) }
        }
}

But you can only conform in one or the other way, but not both! Therefore, for 
trees, we need something like:

protocol TreeLiteralConvertible {
        associatedtype LeafValue
        init(literal: Self.LeafValue...)
        init(literal: Self...)
}

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

Reply via email to