Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of fst and snd for F# struct tuples?

Tags:

f#

If I am using reference tuples, this compiles:

let plot(x: int, y: int) = ()
let point = 3, 4
plot(fst point, snd point)

However, if I am using struct tuples...

let plot(x: int, y: int) = ()
let point = struct (3, 4)
plot(fst point, snd point)

... I get the compiler error, One tuple type is a struct tuple, the other is a reference tuple

What should I do?

like image 872
Wallace Kelly Avatar asked Mar 16 '20 18:03

Wallace Kelly


Video Answer


1 Answers

There's a ToTuple() extension method in System.TupleExtensions for ValueTuple<T1, T2...>.

You could just call:

plot (point.ToTuple())

As for fst, snd, they're bound to System.Tuple<>, so maybe you could define an alternative:

let fstv struct (a,_) =  a
let sndv struct (_,b) =  b
like image 53
Asti Avatar answered Nov 15 '22 10:11

Asti