draft proposal for Sum Types for D
oconnor0
thegreendragon+dlang at gmail.com
Tue Nov 29 16:18:53 UTC 2022
On Tuesday, 29 November 2022 at 15:26:07 UTC, rikki cattermole
wrote:
> Sumtypes are not distinct in the type system. They are like
> alias, its just a collection of values/behavior that is given a
> name.
>
> You would need to use features like templates, conditional
> compilation, UDA's ext. to make it distinct and even then they
> should be implicitly convertible as long as its a superset or
> equal in members.
>
> This extends over to the AST implementation stuff, it means
> there would need to be a global table containing the actual
> instances and when you instantiate a templated sumtype the
> instance would effectively be just an alias into an entry in
> that table.
>
> Like None, the non-distinctiveness of sumtypes is fundamental
> in the type theory and comes from set theory. So its important
> that we get this right, because it has a lot of flow on effects.
Can you explain this a little more? Sumtype constructors/tags
don't necessarily have to be shared across all possible sumtypes.
For example, Ocaml has polymorphic variants that do not tie tags
to types (https://v2.ocaml.org/manual/polyvariant.html) and
variants that do tie tags to types
(https://v2.ocaml.org/manual/coreexamples.html#s:tut-recvariants).
More information about the Digitalmars-d
mailing list