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

Matthew Johnson matthew at anandabits.com
Sat Jul 2 09:30:00 CDT 2016



Sent from my iPad

On Jul 2, 2016, at 9:10 AM, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:

>>> Anton Zhilin via swift-evolution <swift-evolution at ...> writes:
>>> -1 from me. I suggest to wait until we get generic protocols
>>> in Swift 4, then we can use the following:
>>> 
>>> protocol From<T> {
>>>   init(_ from: T)
>>> }
>> 
>> I'm not sure this feature would be relevant in the case of literals.  It
> would definitely require something other than just From.  What specific 
> design would you propose (assuming generic protocols) to replace the 
> protocols impacted by this proposal?
> 
> 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.

> 
> From name and external label are discussable.
> 
> I'd also note that although the two proposals are not orthogonal, they do 
> not strictly conflict. I don't find it too bad if current renaming is 
> applied, and later the whole convertibles system is overhauled.
> 
> It's not globally important, but I've just invented a solution for 
> NilLiteralConvertible. We can make nil a value of type Nil:
> 
> enum Nil { case nil }  // nil keyword is a macro for Nil.nil
> 
> And then From<Nil> will replace NilLiteralConvertible.
> 
> _______________________________________________
> 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