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

Anton Zhilin antonyzhilin at gmail.com
Sat Jul 2 11:47:39 CDT 2016

Dave Abrahams via swift-evolution <swift-evolution at ...> writes:

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

Literals don't have type. But values, which are passed to initializers,
do. Compiler will pick suitable From<T> conformance, depending on
built-in type in which literal can be expressed.

Initialization with a literal can be expressed in two steps:
1. Representation as a suitable built-in type, done by compiler
2. Conversion from that built-in type to our type

It's another way to look at things, which is implemented in Rust.
We can also use this generic protocol for error conversions in 'try'
and all other conversions that we will need.

More information about the swift-evolution mailing list