top | item 41122281

(no title)

paholg | 1 year ago

The difference is mostly a matter of perspective, isn't it?

In Rust, if I have

``` enum Foo { A(u32), B(u32), C(u32), } ```

Then the number of representable states is deduced my an "algebra of numbers", but the size is deduced by an "algebra of sets".

For example, the size of Foo is just 8 (4 bytes for u32, and 4 for the tag + alignment).

discuss

order

marcosdumay|1 year ago

Given the types: I = A + B; J = C; X = A; Y = B + C

Is I + J the same type as X + Y?

If your types are tagged, they aren't. Because that's what tags do.

bombela|1 year ago

My answer would be: No they are not the same type. Yes they have the same amount of bits representing them. They might have different RAM usage because of alignment.

xigoi|1 year ago

> Is I + J the same type as X + Y?

They are not the same, but they are isomorphic. Just like with (A×B)×C versus A×(B×C).

paholg|1 year ago

Okay? I don't know what point you're making.