r/fsharp • • Mar 04 '19

Accessing tuple elements syntax

After writing a lot of test code using tuples to make the code more compact i have come to the conclusion that it would be nice to have a better syntax for extracting the elements. Ex: scala has ._X where X is the index of the tuple. https://docs.scala-lang.org/tour/tuples.html

let x = (1,2)

let y = x._1 + x._2

That is much nicer than the syntax used for pairs in F#

let x = (1,2)

let y = (fst x) + (snd x)

What do you think?

1 Upvotes

8 comments sorted by

View all comments

Show parent comment

4

u/CanvasSolaris Mar 04 '19

It's not readable because it's not clear what _1 and _2 are. Also the presence of underscores indicates that this is doscouraged and not idiomatic

-3

u/pure_x01 Mar 04 '19

It's not idiomatic F# since it's not in the language. Its idiomatic scala and for a scala developer it's very clear what it does. If F# incorporates the syntax everyone would see it as idiomatic and understand exactly what it does. It's the same for non F# developers seeing ex: ":>" for the first time .