[swift-evolution] Reconsidering SE-0003 Removing var from Function Parameters and Pattern Matching

Dave Abrahams dabrahams at apple.com
Fri Jan 29 14:13:04 CST 2016


on Fri Jan 29 2016, Tyler Cloutier <cloutiertyler-AT-aol.com> wrote:

> On Jan 29, 2016, at 8:54 AM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> 
>> on Thu Jan 28 2016, Thorsten Seitz <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>>> This is called flow typing in Ceylon and they are using "exists" for
>
>>> that case but testing for conformance with "is" works just the same
>>> way there. The latter is of importance because the common use of union
>>> types in Ceylon.
>>> 
>>> if exists foo {
>>>        // foo is non-optional here
>>> }
>>> 
>>> if foo is String {
>>>        // foo is of type String here
>>> }
>> 
>> FWIW, some of us are concerned that if the types of names change
>> without being announced by a let or var binding, it will be confusing.
>> That's one reason we haven't gone this way in the past.
>> 
>
> True enough, but is type narrowing (as in the above) really more confusing than
>
> if let x = x {
>
> }

The difference is that in the latter, you don't *have* to shadow.  I've
mostly avoided it, and found the results to be quite good.  There's
usually a more appropriate name for the unwrapped thing.

> Nothing there suggests that the type of x should change, yet it
> does. If eliminating confusion was the goal wouldn't
>
> if let x = x? {
>
> }
>
> be more explicit?

I don't think that addresses the particular confusion we're discussing,
personally.  At least, it wouldn't for me.

> Tyler 
>
>>> -Thorsten
>>> 
>>>> Am 28.01.2016 um 19:08 schrieb Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org>:
>>>> 
>>>>   if bind foo {
>>>>       // foo is non-optional in here
>>>>   }
>>>> 
>>>>   somethingAsync { [weak self] in
>>>>       guard bind self else { return }
>>>>       // ...
>>>>   }
>>>> 
>>>> Elegant when you want to rebind the same name!
>>>> 
>>>> Jacob
>>>> 
>>>>> On Thu, Jan 28, 2016 at 10:05 AM, Erica Sadun via swift-evolution
>>>>> <swift-evolution at swift.org> wrote:
>>>>> Do you realize how much confusion it would save if Swift just went with
>>>>> 
>>>>> if bind foo = bar {...}
>>>>> 
>>>>> with let semantics?
>>>>> 
>>>>> -- Erica
>>>>> 
>>>>>> On Jan 28, 2016, at 11:03 AM, Joe Groff via swift-evolution
>>>>>> <swift-evolution at swift.org> wrote:
>>>>>> 
>>>>>> 
>>>>>>> On Jan 28, 2016, at 12:43 AM, Brent Royal-Gordon <brent at architechies.com> wrote:
>>>>>>> 
>>>>>>>> We have a lot of evidence that 'if var' confuses peopleā€”a lot
>>>>>>>> of users think that 'if var' and 'var' bindings in case
>>>>>>>> patterns will write back to the original value when this isn't
>>>>>>>> the case.
>>>>>>> 
>>>>>>> Can we address this with a diagnostic?
>>>>>>> 
>>>>>>>     var bar: Int? = 1
>>>>>>>     if var foo = bar {
>>>>>>>             foo += 1        // Warning: Value is never used after modification (foo is a copy, not an alias)
>>>>>>>     }
>>>>>>>     print(bar)
>>>>>> 
>>>>>> Good idea.
>>>>>> 
>>>>>> -Joe
>>>>>> _______________________________________________
>>>>>> swift-evolution mailing list
>>>>>> swift-evolution at swift.org
>>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>>> 
>>>>> _______________________________________________
>>>>> swift-evolution mailing list
>>>>> swift-evolution at swift.org
>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>> 
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> -- 
>> -Dave
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>

-- 
-Dave


More information about the swift-evolution mailing list