No we should not support enum types derived from strings
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Tue May 11 22:09:00 UTC 2021
On Tuesday, 11 May 2021 at 21:36:46 UTC, Andrei Alexandrescu
wrote:
> There's no true subtyping or polymorphism with value semantics.
I think you guys need to agree on what you mean by "type" and
"subtype".
Mathematically a type would be a set of states and a set of
operators that can take you between the states. A subtype is
just a reduced set of states/operators where operators keep you
within the set of states.
In OO a type is an abstraction (reduced set) of the states that
the entity you model in The Real World has. A subclass in OO is
increasing the number of states/operators, but decreasing the
number of Real World entities covered.
So these twi notions of "subtype" are opposite.
> primitives across said range of types. With enums that's
> onerous; as soon as you "derive" an enum from int you figure
> that ++x can't reasonably be implemented. Same goes for enum
In C enums are subtypes of int. You reduce the number of states.
C enums are not sound, because operators can take you out of the
allowed set of states in a heartbeat.
Anyway, I've given up following this discussion.
Just define the desirable outcome (practical design) and forget
about the theoretical aspects... then others might be able to
understand where the viewpoints differ.
More information about the Digitalmars-d
mailing list