|
|
|
|
|
by wtetzner
1312 days ago
|
|
The problem is that if you have e.g. let x: u64|i32 = ...
It's impossible for the compiler to do anything with x without adding some kind of runtime type tag. The representations of those types are different.But with something like OCaml's polymorphic variants, you could do e.g. let x: Big(u64)|Small(i32) = ...
and then switch on the tag (Big or Small) to determine what to do with the values. |
|
Yes, in this particular case that's true. If the developer tries to do anything except maybe printing it for debug then the compiler will tell the developer so and the developer will have to switch to sumtypes / wrap it just like it is done in OCaml by default.