Опираясь на ответы @Nghia Bui и @glennsl, вы можете определить свой собственный тип Triple
, используя кортеж из трех элементов для безопасности типов:
type Triple = Triple of int * int * int
with
static member inline (+) (t1, t2) =
match t1, t2 with
| Triple (a1, a2, a3), Triple (b1, b2, b3) -> Triple (a1 + b1, a2 + b2, a3 + b3)
//add other functionality like map, fold, etc you'd normally expect from Arrays
let t1 = Triple (1, 2, 3)
let t2 = Triple (4, 5, 6)
t1 + t2 //val it : Triple = Triple (5,7,9)
Или вы можете сделатьэто универсально:
type GenericTriple<'a> = GenericTriple of 'a * 'a * 'a
with
static member // etc...