logoalt Hacker News

orthoxeroxyesterday at 12:22 PM1 replyview on HN

Third paragraph from the top:

> unions enable designs that traditional hierarchies can’t express, composing any combination of existing types into a single, compiler-verified contract.


Replies

SideburnsOfDoomyesterday at 12:34 PM

It's very unclear which you mean by that.

To me that "compiler-verified" maps to "sealed", not "on the fly". Probably.

Their example is:

public union Pet(Cat, Dog, Bird);

Pet pet = new Cat("Whiskers");

- the union type is declared upfront, as is usually the case in c#. And the types that it contains are a fixed set in that declaration. Meaning "sealed" ?

show 2 replies