I have written this F# code:
let tuples = [|("A",1,0);("A",2,3);("A",3,6)|]
let tupleSubset =
tuples
|> Seq.map(fun values ->
values.[0],
values.[2])
printfn "%A" tupleSubset
I am getting: The operator 'expr.[idx]' has been used on an object of indeterminate type based on information prior to this program point. Consider adding further type constraints
Can anyone tell me what I am doing wrong?
A simple way around the error you are getting would be the following:
let tuples = [|("A",1,0); ("A",2,3); ("A",3,6)|]
let tupleSubset = tuples |> Seq.map (fun (a, b, c) -> a, b)
printfn "%A" tupleSubset
As to why you are getting the error: note that the kind of index dereferencing you are attempting with values.[0]
and values.[1]
works for arrays, dictionaries, etc., but not for tuples, whereas each values
has the type string * int * int
.
Since you don't need the third element of the tuple, you can even choose not to bind it to a symbol, by writing the second line as follows:
let tupleSubset = tuples |> Seq.map (fun (a, b, _) -> a, b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With