gracelang / language

Design of the Grace language and its libraries
GNU General Public License v2.0
6 stars 1 forks source link

Add zip method to Enumerable? #127

Open apblack opened 7 years ago

apblack commented 7 years ago

Should we add a zip(_) method to Enumerables?

[1, 2, 3].zip ["foo", "bar", "biff"] returns [ [1, "foo"], [2, "bar"], [3, "biff" ] ]
KimBruce commented 7 years ago

Sure. Too bad there are no built in tuples, as it makes more sense to give the result as a list of pairs.

kjx commented 7 years ago

I'll let you speculate on what the type of zip should be (if we can't write a good type, perhaps we shouldn't put the function into the library).

Or we can fight over what square brackets should mean. Again.

(Actually, if we really stick to our guns on being "OO" rather than "functional", abstract rather than concrete, co-algebraic rather than algebraic - then writing tuple(x,y) ain't so bad. (Though I'm tempted to spell "tuple" as "data")

Unfortunately we can no longer deconstruct such things in matches.

apblack commented 7 years ago

As I defined it with my single example,

type List⟦X⟧ = {
    ...
    zip(o:List⟦Y⟧) -> List ⟦ List⟦X|Y⟧ ⟧
    ...
}

but it might be more reasonable to have it return a list of bindings:

type List⟦X⟧ = {
    ...
    zip(o:List⟦Y⟧) -> List ⟦ Binding⟦X, Y⟧ ⟧
    ...
}
kjx commented 7 years ago

yes. bindings stand in for 2-tuples - J

On 8/06/2017, at 12:21PM, Andrew Black notifications@github.com wrote:

but it might be more reasonable to have it returns list of bindings: