[HN Gopher] Iterate over Parameter Packs in Swift 6.0
___________________________________________________________________
Iterate over Parameter Packs in Swift 6.0
Author : todsacerdoti
Score : 20 points
Date : 2024-03-08 20:31 UTC (2 hours ago)
(HTM) web link (www.swift.org)
(TXT) w3m dump (www.swift.org)
| jjice wrote:
| This is a very cool feature, but I'm starting to see why people
| say that Swift has crammed every other language's feature into
| one place. Not that that's necessarily bad, but this is a pretty
| specific feature to have that probably won't benefit the majority
| of users (not that that's wrong either).
| MBCook wrote:
| It will because of the mess of functions in some places. There
| are things in the std library defined like this:
|
| a(x1);
|
| a(x1, x2);
|
| a(x1, x2, x3);
|
| Etc. All the same function but with different numbers of
| arguments of the same type. I'm not sure how useful it is to
| everyday programmers, but it lets them fix some messes in the
| standard library. For example how you can only have 10 (?)
| things in a VStack in SwiftUI. Why? It was implemented as above
| because type checked variadic arguments weren't doable for a
| reason I'm not sure of.
|
| Now they are.
| Someone wrote:
| Detailed rationale is in the Swift Evolution proposal
| (https://github.com/apple/swift-
| evolution/blob/main/proposals...)
|
| This also isn't a problem specific to Swift. Many strongly
| typed languages run into it.
|
| Examples:
|
| - C# (https://learn.microsoft.com/en-
| us/dotnet/api/system.tuple-8?...): public
| class Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>
|
| - Scala (https://www.scala-
| lang.org/api/2.13.6/scala/Function22.html):
| trait Function22[-T1, -T2, -T3, -T4, -T5, -T6,
| -T7, -T8, -T9, -T10, -T11, -T12, -T13,
| -T14, -T15, -T16, -T17, -T18, -T19,
| -T20, -T21, -T22, +R] extends AnyRef
|
| - Java (https://www.javatuples.org/index.html; third party)
| adamwk wrote:
| I agree its pretty niche; but i still think its better for
| users, who will probably never interact with it directly, than
| placing an arbitrary ceiling for certain functions
| liuliu wrote:
| But the tuple still cannot conform to Equatable because it is not
| an "existential type"? It is pretty handy when you want to pass
| data around generic type T which is Equatable. Now if you want to
| add a little bit more data (through a tuple), it doesn't work any
| more because tuple of Equatable's cannot be Equatable itself.
| armchairhacker wrote:
| Swift is a great language, but there are many upcoming great
| languages. It competes against Kotlin, Scala, Rust, Zig, Go, and
| in case any other developing languages happen to get wide support
| (seems unlikely now, but remember 15 years ago everything I
| listed except Scala didn't exist, 10 years ago most were in their
| infancy if they existed at all, and 5 years ago Rust and Zig were
| much smaller).
|
| It won't succeed without better cross-platform (at least Linux)
| support, and better integration with IDEs other than Xcode.
___________________________________________________________________
(page generated 2024-03-08 23:01 UTC)