Using helper functions, you can get the same thing from both approaches.
Record
type ComplexRec =
{
real: float
imag: float
}
let buildRec(r,i) =
{ real = r ; imag = i }
let c = buildRec(1.,5.)
c.imag
Connection type
type ComplexUnion =
Complex of
real: float * imag: float
let c = Complex(1.,5.)
let getImag = function
Complex(_,i) -> i
getImag c
I suggest that (frequent) decomposition of a union type can affect performance, but I'm not an expert on this.
source
share