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

Anton Zhilin antonyzhilin at gmail.com
Sat Jul 2 09:10:50 CDT 2016


> >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".

>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.



More information about the swift-evolution mailing list