<div dir="ltr">what about `*LiteralRepresentable`?</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 26, 2016 at 11:11 AM, Hooman Mehr via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Syntax by itself is not clear enough. Appending Initializable makes it too long. </div><div><br></div><div>We can replace Syntax with LiteralSyntax to clarify. Then we will have:</div><div><br></div><div>extension MyNumber: LiteralSyntax.Integer, LiteralSyntax.Float { /*…*/ }<br><div><br></div><div>Better yet, to address the valid concern of doing something so different and hack-like for literals, how about simply <b>renaming *LiteralConvertible protocols to *LiteralSyntax or LiteralSyntax*.</b> The key is the <b>LiteralSyntax</b> phrase which (I think) is the clearest short phrase we can get to communicate the intent. Look: It is right there in the title!</div><div><div><br><div><blockquote type="cite"><div><div class="h5"><div>On Jun 23, 2016, at 8:31 AM, Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></div></div><div><div><div class="h5"><div style="word-wrap:break-word">I have completed a draft of a proposal to move the `*LiteralConvertible` protocols into a `Syntax` namespace as suggested by the standard library team. <div><br></div><div>The draft can be found here: <a href="https://gist.github.com/anandabits/99dad2305d310874bd613b72b14eee56" target="_blank">https://gist.github.com/anandabits/99dad2305d310874bd613b72b14eee56</a>.  It is also included below.</div><div><br></div><div>I will submit a PR in the next day or two after incorporating any feedback.</div><div><br></div><div>-Matthew</div><div><br></div><div><h1 style="font-size:37px;line-height:42px;margin-top:42px;margin-bottom:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Literal Syntax Protocols</h1><ul style="margin-top:21px;margin-bottom:21px;padding-left:1.5em;color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;font-size:15px"><li style="font-size:17px">Proposal: <a style="color:rgb(13,110,161);text-decoration:none">SE-NNNN</a></li><li style="font-size:17px">Author: <a href="https://github.com/anandabits" style="color:rgb(13,110,161);text-decoration:none" target="_blank">Matthew Johnson</a></li><li style="font-size:17px">Status: <strong style="line-height:1">Awaiting review</strong></li><li style="font-size:17px">Review manager: TBD</li></ul><h2 style="color:rgb(17,17,17);font-size:27px;line-height:42px;margin-top:42px;margin-bottom:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Introduction</h2><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">This proposal renames the <code style="line-height:1">*LiteralConvertible</code> protocols to <code style="line-height:1">Syntax.*Literal</code>. </p><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">Swift-evolution thread: <a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/21290" style="color:rgb(13,110,161);text-decoration:none" target="_blank">Revisiting SE–0041 Names</a></p><h2 style="color:rgb(17,17,17);font-size:27px;line-height:42px;margin-top:42px;margin-bottom:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Motivation</h2><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">The standard library currently has protocols that use the term <code style="line-height:1">Convertible</code> in two different ways. The <code style="line-height:1">*LiteralConvertible</code> protocols use the meaning of converting <em style="line-height:1">from</em> a literal. The <code style="line-height:1">Custom(Debug)StringConvertible</code> protocols use the meaning of converting <em style="line-height:1">to</em> a <code style="line-height:1">String</code>. This causes confusion for developers attempting to name their own protocols following the precedence established by the standard library.</p><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">Further, the standard library team has observed:</p><pre style="margin-top:21px;margin-bottom:21px;color:rgb(17,17,17);font-size:15px"><code style="line-height:inherit;display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,248);min-height:auto;background-position:initial initial;background-repeat:initial initial">The <span style="color:rgb(221,17,68)">&quot;literal&quot;</span> protocols are <span style="font-weight:bold">not</span> <span style="font-weight:bold">about</span> conversion, they are <span style="font-weight:bold">about</span> adopting a certain syntax provided <span style="font-weight:bold">by</span> <span style="font-weight:bold">the</span> language.  <span style="color:rgb(221,17,68)">&quot;Convertible&quot;</span> <span style="font-weight:bold">in</span> <span style="font-weight:bold">the</span> <span>name</span> <span style="font-weight:bold">is</span> a red herring: a type can&#39;t be convertible <span style="font-weight:bold">from</span> an <span>integer</span> literal because there <span style="font-weight:bold">is</span> no <span style="color:rgb(221,17,68)">&quot;IntegerLiteral&quot;</span> entity <span style="font-weight:bold">in</span> <span style="font-weight:bold">the</span> type system.  The literal *becomes* typed <span style="font-weight:bold">as</span> <span style="font-weight:bold">the</span> corresponding literal type (e.g., Int <span style="font-weight:bold">or</span> String), <span style="font-weight:bold">and</span> <span style="font-weight:bold">as</span> far <span style="font-weight:bold">as</span> <span style="font-weight:bold">the</span> user <span style="font-weight:bold">at</span> <span style="font-weight:bold">the</span> call site <span style="font-weight:bold">is</span> concerned, there <span style="font-weight:bold">is</span> no visible conversion (even <span style="font-weight:bold">if</span> one <span style="font-weight:bold">is</span> happening <span style="font-weight:bold">behind</span> <span style="font-weight:bold">the</span> scenes)
</code></pre><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em"><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0041-conversion-protocol-conventions.md" style="color:rgb(13,110,161);text-decoration:none" target="_blank">An earlier proposal</a> was intended to address the first problem by introducing strong naming conventions for three kinds of conversion protocols (<em style="line-height:1">from</em>, <em style="line-height:1">to</em>, and <em style="line-height:1">bidirectional</em>). The review highlighted the difficulity in establishing conventions that everyone is happy with. This proposal takes a different approach to solving the problem that originally inspired that proposal while also solving the awkwardness of the current names described by the standard library team.</p><h2 style="color:rgb(17,17,17);font-size:27px;line-height:42px;margin-top:42px;margin-bottom:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Proposed solution</h2><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">This proposal addresses both problems by introducing a <code style="line-height:1">Syntax</code> “namespace” and moving the <code style="line-height:1">*LiteralConvertible</code> protocols into that “namespace” while also renaming them. The proposal <strong style="line-height:1">does not</strong> make any changes to the requirements of the protocols.</p><h2 style="color:rgb(17,17,17);font-size:27px;line-height:42px;margin-top:42px;margin-bottom:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Detailed design</h2><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">All of the <code style="line-height:1">*LiteralConvertible</code> protocols will receive new <code style="line-height:1">*Literal</code> names inside a <code style="line-height:1">Syntax</code>namespace. </p><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">This namespace will initially be implemented using a case-less <code style="line-height:1">enum</code>, but this detail may change in the future if submodules or namespaces are added to Swift. Swift does not currently allow protocols to be declared inside the scope of a type. In order to work around this limitation the protocols themselves will be declared using underscore-prefixed names internal to the standard library. Typealiases inside the <code style="line-height:1">Syntax</code> enum will declare the names intended to be visible to user code.</p><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">This proposal does not change any requirements of these protocols. All requirements of all <code style="line-height:1">*LiteralConvertible</code> protocols will remain exactly the same.</p><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">The following protocol declarations and names:</p><pre style="margin-top:21px;margin-bottom:21px;color:rgb(17,17,17);font-size:15px"><code style="line-height:inherit;display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,248);min-height:auto;background-position:initial initial;background-repeat:initial initial"><span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">NilLiteralConvertible</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">BooleanLiteralConvertible</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">FloatLiteralConvertible</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">IntegerLiteralConvertible</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">UnicodeScalarLiteralConvertible</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">ExtendedGraphemeClusterConvertible</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">StringLiteralLiteralConvertible</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">StringInterpolationLiteralConvertible</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">ArrayLiteralConvertible</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">DictionaryLiteralConvertible</span> </span>{ ... }</code></pre><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">Are changed as follows:</p><pre style="margin-top:21px;margin-bottom:21px;color:rgb(17,17,17);font-size:15px"><code style="line-height:inherit;display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,248);min-height:auto;background-position:initial initial;background-repeat:initial initial">
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_NilLiteralSyntax</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_BooleanLiteralSyntax</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_IntegerLiteralSyntax</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_FloatLiteralSyntax</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_UnicodeScalarLiteralSyntax</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_ExtendedGraphemeClusterLiteralSyntax</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_StringLiteralLiteralSyntax</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_StringInterpolationLiteralSyntax</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_ArrayLiteralSyntax</span> </span>{ ... }
<span style="font-weight:bold">public</span> <span><span style="font-weight:bold">protocol</span> <span style="color:rgb(68,85,136);font-weight:bold">_DictionaryLiteralSyntax</span> </span>{ ... }

<span style="font-weight:bold">public</span> <span style="color:rgb(153,153,136);font-style:italic">/* closed */</span> <span><span style="font-weight:bold">enum</span> <span style="color:rgb(68,85,136);font-weight:bold">Syntax</span> </span>{
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>NilLiteral</span> = _NilLiteralSyntax
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>BooleanLiteral</span> = _BooleanLiteralSyntax
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>IntegerLiteral</span> = _IntegerLiteralSyntax
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>FloatLiteral</span> = _FloatLiteralSyntax
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>UnicodeScalarLiteral</span> = _UnicodeScalarLiteralSyntax
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>ExtendedGraphemeClusterLiteral</span> = _ExtendedGraphemeClusterLiteralSyntax
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>StringLiteralLiteral</span> = _StringLiteralLiteralSyntax
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>StringInterplolationLiteral</span> = _StringInterpolationLiteralSyntax
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>ArrayrLiteral</span> = _ArrayLiteralSyntax
  <span style="font-weight:bold">public</span> <span style="font-weight:bold">typealias</span> <span>DictionaryLiteral</span> = _DictionaryLiteralSyntax
}</code></pre><h2 style="color:rgb(17,17,17);font-size:27px;line-height:42px;margin-top:42px;margin-bottom:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Impact on existing code</h2><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">All code that references any of the <code style="line-height:1">*LiteralConvertible</code> protocols will need to be modified to reference the protocol via the new <code style="line-height:1">Syntax.*Literal</code> name.</p><h2 style="color:rgb(17,17,17);font-size:27px;line-height:42px;margin-top:42px;margin-bottom:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Alternatives considered</h2><h3 style="color:rgb(17,17,17);margin:21px 0px;font-size:20px;line-height:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Protocol names</h3><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">Several commenters have suggested that the names in this proposal are confusing at the site of use:</p><pre style="margin-top:21px;margin-bottom:21px;color:rgb(17,17,17);font-size:15px"><code style="line-height:inherit;display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,248);min-height:auto;background-position:initial initial;background-repeat:initial initial"><span><span style="font-weight:bold">struct</span> <span style="color:rgb(68,85,136);font-weight:bold">Foo</span>: <span style="color:rgb(68,85,136);font-weight:bold">Syntax</span>.<span style="color:rgb(68,85,136);font-weight:bold">IntegerLiteral</span> </span>{ ... }</code></pre><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">One alternative naming scheme would emphasize the semantic of initializing the type with a literal:</p><pre style="margin-top:21px;margin-bottom:21px;color:rgb(17,17,17);font-size:15px"><code style="line-height:inherit;display:block;padding:0.5em;color:rgb(51,51,51);background-color:rgb(248,248,248);min-height:auto;background-position:initial initial;background-repeat:initial initial"><span><span style="font-weight:bold">struct</span> <span style="color:rgb(68,85,136);font-weight:bold">Foo</span>: <span style="color:rgb(68,85,136);font-weight:bold">Syntax</span>.<span style="color:rgb(68,85,136);font-weight:bold">IntegerLiteralInitializable</span> </span>{ ... }</code></pre><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">Discussion of the pros and cons of the proposed and alternative naming schemes is encouraged. The core team should feel free to make a final decision on the exact naming scheme used if they choose to accept this proposal.</p><h3 style="color:rgb(17,17,17);margin:21px 0px;font-size:20px;line-height:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Previous proposal</h3><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">This proposal is a follow up to <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0041-conversion-protocol-conventions.md" style="color:rgb(13,110,161);text-decoration:none" target="_blank">Updating Protocol Naming Conventions for Conversions</a>. Many related alternatives were explored during the discussion and review of that proposal.</p><h2 style="color:rgb(17,17,17);font-size:27px;line-height:42px;margin-top:42px;margin-bottom:21px;font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif">Acknowledgements</h2><p style="color:rgb(17,17,17);font-family:&#39;Helvetica Neue&#39;,Helvetica,Arial,Verdana,sans-serif;word-wrap:break-word;margin:1.3125em 0px;font-size:1.1429em;line-height:1.3125em">The design described in this proposal was suggested by Dave Abrahams, Dmitri Gribenko, and Maxim Moiseev.</p></div></div></div></div>_______________________________________________<span class=""><br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></blockquote></div><br></div></div></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>