[swift-evolution] Proposal Draft: Optional Upgrading Assignment.
Chris Lattner
clattner at apple.com
Thu Feb 4 11:35:44 CST 2016
> On Feb 4, 2016, at 12:28 AM, Paul Ossenbruggen via swift-evolution <swift-evolution at swift.org> wrote:
>
> Draft Proposal feedback welcome.
>
> ## Introduction
>
> Currently to make a optional from a value the type name must be repeated:
>
> let x = “Some Value”
> let y : String? = x
>
> This takes away some of the advantage of type inference because the very next line I must specify the type.
>
> ## Proposal
>
> I propose the following syntax:
>
> let y? = x
This syntax already means something in Swift (though in this context it is illegal): "a?” is a pattern that binds to the inside of an optional. It actually does the opposite of what you propose: it binds “a” to the thing inside an optional, which is the opposite of what you want.
As others have pointed out, using "Optional(x)” works today in an arbitrary expression position.
-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160204/2442d67d/attachment.html>
More information about the swift-evolution
mailing list