Hello dear D community,

I need to express a system of related types. The values are actually values, 
meaning I absolutely need value semantics (no referencing, else I would be 
forced to explicitely copy on each assignment). Also, they are structured, 
record-like thingies.
I was very pleased to discover that D has class-like structs: we can define 
methods and even custom constructors. Even nicer, it provides a kind of literal 
notation for struct "specimens" (instances). This brings me handy plain value 
records. Great!

But for any reason, this logic is not pushed to the point of providing type 
hierarchy by subtyping. It would have been great for me, since much of the 
common functionality is generic. Without a type hierarchy, I need to duplicate 
it on each struct type, which is _bad_ (as any programmer knows ;-).

I would like to learn about possible workarounds, or other alternative 
approaches to such problems, if ever you now any. Also, I would love to read 
about the rationale for _not_ having struct type hierarchies (probably this 
would not be a big deal, since D has it for classes (*)) Or maybe I have simply 
not correctly understood available docs?


Thank you,
Denis

(*) Oberon is rather close to D on this point: it has records with "type-bound 
procedures" (read "methods"). But these records are "extendable" (read 
"subtype-able"). Methods are bound via dynamic (single) dispatch. D-like 
classes are provided by record-pointer types, on instances of which 
dereferencing is automatic (when accessing slots) (only the type def 
explicitely mentions reference).
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com

Reply via email to