The operator you described is essentially the map
function for a two-element tuple. The map
function, in general has a signature (for some F<'a>
which could be seq<'a>
or many other types in F# libraries):
map : ('a -> 'b) -> F<'a> -> F<'b>
So, if you define F<'a>
as a two element tuple, then your function is actually just map
(if you flip the arguments):
type F<'a> = 'a * 'a
let map f (a, b) = (f a, f b)
The operation is not built-in anywhere in the F# library, but it is useful to realize that it actually matches a pattern that is quite common in F# libraries elsewhere (list, seq, array, etc.)
Looking at the Haskell answer referenced by @pad - in principle, Haskell makes it possible to define the same function for all types that support such operations using type classes (so you would write just fmap
instead of Seq.map
or instead of your TwoElementTuple.map
, but it actually does not work for various technical reasons - so Haskellers need to call it differently).
In F#, this is not easily possible to define a single map
function for different types, but you can still think of your function as a map
for two-element tuples (even if you find it easier to give it a symbolic operator name, rather than the name map
.)