[swift-evolution] Proposal: Always flatten the single element tuple

Jens Persson jens at bitcycle.com
Thu Jun 8 11:09:12 CDT 2017


I just want to say, as a "regular developer", that I'm with Vladimir S here.

Swift 3 (and current Swift 4) both still have a lot of inconsistencies
and/or bugs related to tuple- and function types which will need to be
fixed before ABI stability, and they are not fixed by going back to a state
with even more inconsistencies.

FWIW I can't see how SE-0110 can be considered fully implemented, and this
is simply because the most recent compiler still cannot properly
"Distinguish between single-tuple and multiple-argument function types"
(that's the title of SE-0110), this is evident in lots of different ways,
here are some of them:

https://bugs.swift.org/browse/SR-5127
Single-tuple and multiple-argument function types should not be considered
equal

https://bugs.swift.org/browse/SR-5128
Don't allow swapping a single-tuple function with a multiple-argument
function

https://bugs.swift.org/browse/SR-5129
Don't treat func signatures as being the same when they are in fact
different

https://bugs.swift.org/browse/SR-5130
Single-tuple and multiple-argument function types should be treated as
different types

I think of the "regression"/decreased ergonomics as a price that is worth
paying for, and a necessary step towards, getting the language in a state
in which it is possible to get rid of Swift's current parentheses-related
inconsistencies and possibly reimplement the hopefully just temporarily
lost ergonomics and/or expressiveness.

Another related "regression" that I think is worth noting has to do with
generics, namely the inability to have type parameters for function types
in this form: Parameter -> Result. This is no longer possible in Swift 4
and it will instead require special casing for each number of parameters in
the function types. This means that it is also impossible to make a type
generic over just function types (wihtout special casing for parameter
count). These things were (sort of) possible to do in earlier versions, but
they couldn't make it all the way without other parts of the language
falling apart. They certainly hinted about something nice, and maybe if the
language is allowed to be simplified and made more consistent, they can be
reimplemented in a proper way.

/Jens


On Thu, Jun 8, 2017 at 3:26 PM, Vladimir.S via swift-evolution <
swift-evolution at swift.org> wrote:

> On 08.06.2017 9:43, Jonathan Hull wrote:
>
>> Also, I want to repeat what I said on the other thread.  We should revert
>> to Swift 3 behavior for this, and then take the time to design the behavior
>> we really want (either for 4.1 or 5).  Anything else will cause us to break
>> people’s code twice…
>>
>
> Yes, *just* ignore/revert a number of connected, actively discussed and
> accepted, implemented(partially for some) proposals, freeze the current
> broken state of function types for very long period without any ability in
> near feature to fix it.
>
> Instead of improvement of the syntax of the problematic parts of code even
> after release (if not possible to suggest a suitable solution before the
> release). I don't think that *improvements* in syntax can break people's
> code.
>
> Huh..
>
>
>> Thanks,
>> Jon
>>
>> On Jun 7, 2017, at 11:50 AM, Gwendal Roué via swift-evolution <
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>
>>>
>>>
>>> Le 7 juin 2017 à 20:33, Gwendal Roué <gwendal.roue at gmail.com <mailto:
>>>> gwendal.roue at gmail.com>> a écrit :
>>>>
>>>> For example, take those three functions:
>>>>
>>>> func f(_ closure:(Int, Int) -> ())
>>>> func g(_ closure:((Int, Int)) -> ())
>>>> func h(_ closure:((a: Int, b: Int)) -> ())
>>>>
>>>> If one can always write (as in Swift 3):
>>>>
>>>> f { (a, b) in ... }
>>>> g { (a, b) in ... }
>>>> c { (a, b) in ... }
>>>>
>>>> Then one can easily deal with a badly fit closure signature.
>>>>
>>>> This is most examplified by dictionaries. They always expose (key: Key,
>>>> value: Value) tuples (their Element type). Problem is that 'key' and
>>>> 'value' are identifiers that only matter for dictionaries, not for
>>>> dictionary users. It's very important for dictionary users to forget about
>>>> tuples, and the `key` and `value` words:
>>>>
>>>> // No pollution
>>>> dictionary.map { (name, score) in ... }
>>>>
>>>
>>> It looks like some people in this mailing list are horrified by this
>>> "request" (not a feature request, but a request that Swift 3 behavior is
>>> restored, actually).
>>>
>>> What could be the reasons for such a bad reaction?
>>>
>>> 1: measurable runtime overhead (slower programs in some cases, without
>>> any obvious way for the developper to notice where is the extra cost)
>>> 2: measurable compiler overhead (slower compilation)
>>> 3: implementation complexity (slower swift progress, technical debt,
>>> etc.)
>>> 4: other?
>>>
>>> I understand 1. We are all fascinated by C++ and Rust "zero-overhead".
>>> If this is the main concern of the community, then we may focus the
>>> discussion of that very precise topic.
>>>
>>> I can live with 2 (just a personal subjective preference)
>>>
>>> About 3: I can not tell because I lack the necessary skills.
>>>
>>> 4: enlighten us!
>>>
>>> Gwendal
>>>
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto: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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170608/fe436603/attachment.html>


More information about the swift-evolution mailing list