[swift-evolution] [Proposal Draft] Literal Syntax Protocols

Adrian Zubarev adrian.zubarev at devandartist.com
Wed Jun 29 01:44:53 CDT 2016


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 (adrian.zubarev at devandartist.com) 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160629/2633340a/attachment.html>


More information about the swift-evolution mailing list