logoalt Hacker News

mwkaufmatoday at 2:07 PM3 repliesview on HN

Looks like it's "just" type-erasure / syntactical sugar. E.g. value types are boxed.


Replies

functional_devtoday at 4:13 PM

Right, the default boxes into heap, but unions are different. Some languages pack them as a flat struct (tag + payload, no allocation).

Here is visual layout if anyone is interested - https://vectree.io/c/memory-layout-tagging-and-payload-overl...

show 1 reply
AndrewDuckertoday at 2:15 PM

Yes, but see the section on custom unions* - you can write non-boxing unions/generators.

* https://devblogs.microsoft.com/dotnet/csharp-15-union-types/...

show 1 reply
celeriestoday at 2:29 PM

Yes, but that's just the default behavior. You can implement your own non-boxing version for performance critical applications.

show 1 reply