Now that tuple
is just record
in SML, I tried:
The codes above I hope this record can accept a tuple, but it reports an error.
So, there's no implicit conversion from tuple to record and from record to tuple(though didn't post here, I have tried at local actually).
My question is why SML doesn't supply such conversion?(because these conversions are quite frequent in c++)
Tuples are records with members named 1 through n. That is, the three element tuple (a, b, c)
is really a record {1 = a, 2 = b, 3 = c}
. So there doesn't need to be an implicit conversion between tuples and records because they're already the same thing.
Now the function you defined takes a record with the members x
, y
and z
and you pass it a record with the members 1
, 2
and 3
. This doesn't work. For this to work there'd need to be an implicit conversion between records with different member names, which seems like a very bad idea.
(because these conversions are quite frequent in c++)
There are no implicit conversions in C++ between unrelated structs or classes with different members (or even the same members). To do that, you'd need a reinterpret_cast
(or a C-style pointer cast on the address), which is neither common nor a good idea (and wouldn't work with anything but POD types).