[swift-evolution] [Review] SE-0115: Rename Literal Syntax Protocols

Matthew Johnson matthew at anandabits.com
Sat Jul 2 10:02:21 CDT 2016


> On Jul 2, 2016, at 9:39 AM, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Matthew Johnson via swift-evolution <swift-evolution at ...> writes:
> 
>>>>> protocol From<T> {
>>>>>  init(_ from: T)
>>>>> }
>>>> 
>>> With From definition given above, I would define 
> IntLiteralConvertible === 
>>> From<Int>, BoolLiteralConvertible === From<Bool>, etc. That means, 
> if you 
>>> conform to From<T> where T is one of Int, Bool, ... then the type 
> becomes 
>>> "literal convertible".
>> 
>> But that doesn't capture the semantics of these protocols.  See the 
> observations made by the library team
>> quoted in the motivation section as well as Dave Abrahams' comments 
> quoted in the alternatives section. 
>> None of this changes if we get generic protocols.  
>> 
>> Protocols aren't just about the syntax, they are also about semantics.  
> These protocols encode specific
>> and important semantics.
> 
> But as some of them noted in the discussion, low-level protocols that 
> interact with language syntax can focus on syntax entirely. I've not 
> seen this point supported by other team members, though.

Yes, but they need to be precise about the syntax they are supporting.  Dave Abrahams has pointed out very clearly why “initialize with an x” is not the correct semantics for the syntax represented by these protocols.

> 
> Personally, I don't see any semantics in LiteralConvertible protocols. 
> If a type can be initialized with another type, then we can call it a 
> conversion. And I can't imagine any case where e.g. Bool that came from 
> a literal should be treated differently from any other Bool.

You might want to take a look at John McCall’s thread about cleaning up the semantics of `MyIntegerLiteralConvertibleType(42)` if you haven’t already.  http://thread.gmane.org/gmane.comp.lang.swift.evolution/19525/focus=19644

> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list