sumtype 0.3.0
jmh530
john.michael.hall at gmail.com
Wed May 9 15:29:25 UTC 2018
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.
More information about the Digitalmars-d-announce
mailing list