[swift-evolution] Fwd: let type binding

Taras Zakharko taras.zakharko at uzh.ch
Thu Dec 17 06:26:38 CST 2015


This would make the semantics of the language dramatically more complicated. In essence, what you suggest here is scope-dependent typing of variables. While interesting in principle (a static language with compile-type dynamic typing? yes please!), this is subtle but quite a big change to the language that can potentially open a can of worms elsewhere.  I believe one should carefully consider the ramifications first — and no, I don’t have any suggestions yet what these ramifications might be.  

Cheers, 

 Taras


> Begin forwarded message:
> 
> From: James Campbell via swift-evolution <swift-evolution at swift.org>
> Subject: [swift-evolution] let type binding
> Date: 17 December 2015 at 12:59:05 GMT+1
> To: swift-evolution <swift-evolution at swift.org>
> Reply-To: James Campbell <james at supmenow.com>
> 
> Currently swift lets you to bind a value to let once:
> 
> i.e 
> 
> let value: UIViewController
> 
> if (condition)
> {
>    value = controllerA
> }
> else
> {
>   value = controllerB
> }
> 
> But currently I have to cast the variable within these blocks to access the property. It would be great if Swift could treat the let value as being the type of the object I am setting just for this closure/block (Obviously we can only set it to a value that matches the type above.)
> 
> So I could literally go like this:
> 
> let value: UIViewController
> 
> if (condition)
> {
>    value = controllerA
>    value.controllerAProperty = []
> }
> else
> {
>   value = controllerB
>   value.controllerBProperty = []
> }
> 
> -- 
>  Wizard
> james at supmenow.com <mailto:james at supmenow.com>
> +44 7523 279 698
>  _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151217/140cbcd7/attachment.html>


More information about the swift-evolution mailing list