On Wednesday, 9 May 2018 at 14:56:20 UTC, Paul Backus wrote:
[snip]
What length actually does, after all the compile-time stuff is
expanded, is essentially this:
switch(v.tag)
{
case 0: return sqrt(v.value!Rectangular.x**2 +
v.value!Rectangular.y**2);
case 1: return v.value!Polar.r;
}
It's the same thing you'd get if you were implementing a tagged
union by hand in C.
It's not exactly the same as a function specialized for
Rectangular, because the entire point of a sum type or tagged
union is to allow runtime dispatch based on the tag. However,
the process of choosing which function goes with which tag
takes place entirely at compile time.
Thanks. That makes sense.