Live data from Hacker News

List Comprehension in Swift

duan.ca

1–10 of 32 posts

Re: List Comprehension in Swift

#2
> List comprehension should be no stranger to a Python or (and?) Haskell user. It’s a really compact syntax that deals with Cartesian product [emphasis mine] of lists.

Ugh, no. I fail to see where the Cartesian product is in::

    [(x,y,z) | x 
---

@dennisvennink

What you feel doesn't matter. It's not a zip.

Re: List Comprehension in Swift

#4

> List comprehension should be no stranger to a Python or (and?) Haskell user. It’s a really compact syntax that deals with Cartesian product [emphasis mine] of lists. Ugh, no. I fail to see where the Cartesian product is in:: [(x,y,z) | x --- @dennisvennink What you feel doesn't matter. It's not a zip.

I'm not sure of the original intent, but you could approach this as the Cartesian product of [1..5] * [1..10] * [1..10] which is then filtered such that the 2nd value is not smaller than the first, and the 3rd value is inclusively between the two

Re: List Comprehension in Swift

#5
post #4

> List comprehension should be no stranger to a Python or (and?) Haskell user. It’s a really compact syntax that deals with Cartesian product [emphasis mine] of lists. Ugh, no. I fail to see where the Cartesian product is in:: [(x,y,z) | x --- @dennisvennink What you feel doesn't matter. It's not a zip.

I'm not sure of the original intent, but you could approach this as the Cartesian product of [1..5] * [1..10] * [1..10] which is then filtered such that the 2nd value is not smaller than the first, and the 3rd value is inclusively between the two

A subset of a Cartesian product is not a Cartesian product. inb4, spare me the wisecrack “It's the Cartesian product of itself and no other factors”.

Re: List Comprehension in Swift

#6

> List comprehension should be no stranger to a Python or (and?) Haskell user. It’s a really compact syntax that deals with Cartesian product [emphasis mine] of lists. Ugh, no. I fail to see where the Cartesian product is in:: [(x,y,z) | x --- @dennisvennink What you feel doesn't matter. It's not a zip.

Indeed. Feels more like a zip (or convolution) to me.

Re: List Comprehension in Swift

#8

> (Can’t wait until we can have variadic generic parameters!) This.

It's a genuinely hard problem. There are proposals for Rust, but nothing actionable. Catching up with all the other cool things takes precedence. (side-note: Rust dodged the problem by using macros. As a C++ guy, I was a little uneasy with this, but they're _mostly_ hygenic)

Re: List Comprehension in Swift

#9
post #4

Earlier quoted context omitted.

I'm not sure of the original intent, but you could approach this as the Cartesian product of [1..5] * [1..10] * [1..10] which is then filtered such that the 2nd value is not smaller than the first, and the 3rd value is inclusively between the two

A subset of a Cartesian product is not a Cartesian product. inb4, spare me the wisecrack “It's the Cartesian product of itself and no other factors”.

> It’s a really compact syntax that deals with Cartesian product of lists.

Couldn't taking the subset of a Cartesian product be considered to be dealing with one?

Re: List Comprehension in Swift

#10
I really dislike the proposed way to do this. If this is "Swifty", give me something else.

The Haskell list comprehension made sense to me the first time I saw it, but there is no way I'd know what the mess in the article was doing until someone explained to me.

Design has to come first. You can't just go with what's "Swifty" if that doesn't convey what's happening in a reasonable fashion.

Post reply on HN