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

Dave Abrahams dabrahams at apple.com
Sat Jul 2 10:37:03 CDT 2016

on Sat Jul 02 2016, Anton Zhilin <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.
> 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.

Because there's no source type.  When you write a literal, you're not
converting *from* anything.


More information about the swift-evolution mailing list