I commonly have a "oh yeah" moment writing F# when I realize I need an extra value somewhere. This is generally easily done by adding another value to the tuple being passed around. However, this means that various maps/sorts/collects/etc. need updating, and in particular the functions fst/snd only work on tuples of length 2.
It's not a huge issue, but it's annoying enough during exploratory development that I though I'd write a helper to alleviate the annoyance:
let inline get2 (t:^a) = (^a : (member get_Item2 : unit -> string) (t, ()))
let inline get2a (t:^a) = (^a : (member Item2 : string) t)
However, both versions do not work. The first, get2
, won't compile, with "Expected 1 expressions, got 2". The second, get2a
, will compile, but subsequently can't be used on tuples: "The type '(int * string)' does not support any operators named 'get_Item2'".
Is there any way of doing this that doesn't involve lots of overloads? with noisy (annotations not required in F# 2.0)OverloadID
annotations