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

Dave Abrahams dabrahams at apple.com
Tue Jun 28 15:57:45 CDT 2016

on Thu Jun 23 2016, Nate Cook <swift-evolution at swift.org> wrote:

> I like the namespace-based approach to group these protocols together
> and I'm very happy to see some clarification happening in this group
> of protocols. However, I don't think the proposed new names
> communicate what they need to. The names listed in the "Alternatives
> Considered" section do a better job of describing the use and behavior
> of these protocols.
> Primarily, the new names read like we're saying that a conforming type
> is a literal, compounding a common existing confusion between literals
> and types that can be initialized with a literal. 

No, it's exactly the opposite, as I keep saying.  Conformance to this
protocol does *not* mean you can initialize the type with a literal.

  func f<T: IntegerLiteralConvertible>() -> T {
    return T(integerLiteral: 43) // Error
    return T(43)                 // Also an Error

It means an instance of the type can be *written* as a literal:

  func f<T: IntegerLiteralConvertible>() -> T {
    return 43   // OK

Everybody's confused about the meaning of the protocol, and doesn't like
the proposed names because they imply exactly the actual meaning of the
protocol, which they misunderstand.


More information about the swift-evolution mailing list