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

Adrian Zubarev adrian.zubarev at devandartist.com
Wed Jun 29 01:57:31 CDT 2016


And just as a side note: the example does work like this:

func f<T : IntegerLiteralConvertible>() -> T {
    return T(integerLiteral: 43 as! T.IntegerLiteralType) // Error
}

func g<T : IntegerLiteralConvertible where T.IntegerLiteralType == Int>() -> T {
     
    return T(integerLiteral: 43)
}

let test: Int = f()
let test2: Int = g()
I assume everyone does know that. The example by itself shows us that literals are in fact typeless until they’re converted into a real type.



-- 
Adrian Zubarev
Sent with Airmail

Am 29. Juni 2016 um 08:48:30, Dave Abrahams via swift-evolution (swift-evolution at swift.org) schrieb:


on Tue Jun 28 2016, Erica Sadun <swift-evolution at swift.org> wrote:

>> On Jun 28, 2016, at 9:21 PM, Sean Heber <sean at fifthace.com> wrote:
>>  
>> IntegerLiteralExpressable?
>>  
>> Does Apple employ any philosophers? We might need one...
>>  
>> l8r
>> Sean
>>  
>
> Aaaaaand...welcome to last night.
>
> The problem being, that people see this and think that the type can be
> expressed as an integer literal,  

**Which is almost exactly the right interpretation, as I keep pointing
out.** How can this be considered a valid argument against that name?

> not that an integer literal can be expressing the type.
> (I won't even bring up other associations for that word since most of
> the subscribers of this mailing list have not been nursing mothers
> although some may be familiar with the technique.)
>
> -- E
>
>>  
>>> On Jun 28, 2016, at 10:02 PM, Erica Sadun <erica at ericasadun.com> wrote:
>>>  
>>>  
>>>> 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
>>>  
>>>  
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

--  
Dave

_______________________________________________
swift-evolution mailing list
swift-evolution at swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160629/76757fbc/attachment.html>


More information about the swift-evolution mailing list