<div dir="ltr">I think it would make sense if a postfix &quot;?&quot; would make the variable optional:<div><br></div><div>    var x = &quot;some string&quot;?</div><div>    x = nil  // allowed because x has type Optional&lt;String&gt;</div><div><br></div><div>This parallels the optional pattern: `if case &quot;foo&quot;? = x { ... }`</div><div><br><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob</div></div></div></div>
<br><div class="gmail_quote">On Sun, Mar 27, 2016 at 3:13 PM, Maximilian Hünenberger <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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div></div><div>Only to be complete:</div><div><br></div><div>let str1 = String?() // nil</div><div>let str2 = String?(&quot;&quot;) // &quot;&quot;</div><div><br></div><div>Kind regards</div><div>- Maximilian</div><div><div class="h5"><div><br>Am 24.03.2016 um 11:57 schrieb Hugues Bernet-Rollande via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div>Hey All,<div><div><br></div><div>I think Andrew already nailed my proposal.</div><div><br></div><div>Thank you all.</div><br><div><p style="margin-bottom:0px;font-stretch:normal;line-height:normal;font-family:Avenir;min-height:19px"><br></p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;">Hugues BERNET-ROLLANDE</p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;;min-height:16px"><br></p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;">--</p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;"><a href="mailto:hugues@xdev.fr" target="_blank">hugues@xdev.fr</a></p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;"><a href="http://www.xdev.fr" target="_blank">http://www.xdev.fr</a></p><p style="margin-bottom:0px;font-stretch:normal;line-height:normal;font-family:Avenir;min-height:19px">





</p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;"><a href="http://www.linkedin.com/in/huguesbr" target="_blank">http://www.linkedin.com/in/huguesbr</a></p></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
  On Mar 24 2016, at 11:56 am, Dan Raviv &lt;<a href="mailto:dan.raviv@gmail.com" target="_blank">dan.raviv@gmail.com</a>&gt; wrote:
  <br>
  <div dir="ltr">Hi Hughes,<div><br></div><div>What&#39;s wrong with:<br>let s = Optional(String(&quot;abc&quot;))<br></div><div><br></div></div><div><br><div>On Thu, Mar 24, 2016 at 12:22 PM, Hugues Bernet-Rollande 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 style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div>In a strongly typed language, such as Swift is, type inference is greatly appreciated as it declutter the instance type definition.<div><div><br></div><div>For example, in the following statement, the compiler easily deduct the type of `aString` by the return type of `String.init()`</div><div><br></div><div>```</div><div>let aString = String()</div><div>```</div><div><br></div><div>Optional are generic enum which can contain a value of a generic type or nil (<a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift" target="_blank">https://github.com/apple/swift/blob/master/stdlib/public/core/Optional.swift</a>)</div><div><br></div><div><span style="line-height:19.6px">Sometime you may want specify that the instance is of type optional in which even if you are a the same time assigning a value to this instance.</span></div><div><span style="line-height:19.6px">In which case you loose the type inference mechanism and you have to define both (the optionality as well as the type). </span></div><div style="line-height:19.6px">For example, you may want specify an optional String with a default value.</div><div><br></div><div>```</div><div>var a:String? = String()</div><div>// or</div><div>var b = String() as String?</div><div>// or</div><div>var c:Optional&lt;String&gt; = String()<br></div><div>```</div><div><br></div><div>But the compiler can already infer the variable type from this assignment, it just miss the &quot;optionality&quot; of the variable.</div><div>It would be nice to be able to express this.</div><div><br></div><div>Then for, I propose the following syntax evolution:</div><div><br></div><div>```</div><div>var a:? = String()</div><div>// and/or (not recommended because more prone to typo and unclear...)</div><div>var a = String() as?</div><div>```</div><div><br></div><div>This would allow for more synthetic optional declaration.</div><div><br></div><div>I&#39;ve draft a proposal on my `swift-evolution` fork:</div><div><span style="white-space:pre-wrap">        </span><span style="line-height:1.4"><a href="https://github.com/huguesbr/swift-evolution/blob/optionality-type-with-type-inference/proposals/0057-optionality-type-with-type-inference.md" target="_blank">https://github.com/huguesbr/swift-evolution/blob/optionality-type-with-type-inference/proposals/0057-optionality-type-with-type-inference.md</a></span></div><div><span style="line-height:1.4"><br></span></div><div><span style="line-height:1.4">Let me know what you think.</span></div><div><br></div><div><p style="margin-bottom:0px;font-stretch:normal;line-height:normal;font-family:Avenir;min-height:19px"><br></p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;">Hugues BERNET-ROLLANDE</p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;;min-height:16px"><br></p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;">--</p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;"><a href="mailto:hugues@xdev.fr" target="_blank">hugues@xdev.fr</a></p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;"><a href="http://www.xdev.fr" target="_blank">http://www.xdev.fr</a></p><p style="margin-bottom:0px;font-stretch:normal;line-height:normal;font-family:Avenir;min-height:19px">





</p><p style="margin-bottom:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:&#39;Sofia Pro Light&#39;"><a href="http://www.linkedin.com/in/huguesbr" target="_blank">http://www.linkedin.com/in/huguesbr</a></p></div></div></div><br>_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
</blockquote></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></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></div></div>