In fact this doesn’t tell you that you can do this:

func f<T : Syntax.Literal.IntegerProtocol>() -> T {
    return T(integerLiteral: 43) // Error
    return T(43) // Also an Error
}
As I already said, literals will be read and converted to an actual type, but 
to adopt this, your time needs conformance to a protocol (sounds trivial?). The 
only direction we have is literal -> type. Should always remember this.

With this in mind, this example is crystal clear:

func f<T : Syntax.Literal.IntegerProtocol>() -> T {
    return 43 // OK
}
I’m only suggesting a clean design here, do what ever you want :P



-- 
Adrian Zubarev
Sent with Airmail

Am 29. Juni 2016 um 08:31:05, Adrian Zubarev ([email protected]) 
schrieb:

How about:

public enum Syntax {
      
    public enum Literal {

        public typealias NilProtocol = ...
        public typealias BooleanProtocol = ...
        public typealias IntegerProtocol = ...
        public typealias FloatProtocol = ...
        public typealias UnicodeScalarProtocol = ...
        public typealias ExtendedGraphemeClusterProtocol = ...
        public typealias StringProtocol = ...
        public typealias StringInterpolationProtocol = ...
        public typealias ArrayProtocol = ...
        public typealias DictionaryProtocol = ...
    }
}

extension Array : Syntax.Literal.ArrayProtocol { ... }


-- 
Adrian Zubarev
Sent with Airmail
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to