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

Erica Sadun erica at ericasadun.com
Tue Jun 28 22:02:38 CDT 2016


> On Jun 28, 2016, at 8:08 PM, Sean Heber <sean at fifthace.com> wrote:
> 
> What about..
> 
> Syntax.ConvertibleFromIntegerLiteral
> etc..

I like it but Dave has already expressed that this isn't conversion. This
is something distinct, magical, and more importantly, ineffable.

He says it means an instance of the type can be written as a literal, and
not converted from a literal. He writes:

> Conformance to this protocol does *not* mean you can initialize the type with
> a literal. 
> 
> Proof:
> 
>  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
>  }
>> 

So we're looking at something more like:

Syntax.AnIntegerLiteralCanBeSubstitutedForThisTypeAndTheCompilerWillNotBarf

-- E




More information about the swift-evolution mailing list