I've made a language! \o/ Introducing Neat
Quirin Schroll
qs.il.paperinik at gmail.com
Wed Sep 21 10:53:56 UTC 2022
On Sunday, 18 September 2022 at 20:28:58 UTC, FeepingCreature
wrote:
> Alright, since I've ran out of critical issues on my TODO,
> here's Neat!
>
> https://neat-lang.github.io/
>
> https://github.com/neat-lang/neat
Can you show a little bit of your sum types? They can be
implemented in four ways:
1. Stupid union (like `union` in C, C++, and D)
2. Type union or soft discriminated union (`int+string+int` =
`int+string` = `string+int`)
3. Indexed union or hard discriminated union (`int+int` ≠ `int`)
For 2., you effectively ask: Which types are in? Order and
repetition don’t matter.
And 3. is effectively an algebraic type with unary constructors
that are referred to by index (instead of by name).
There are even more options like `int+string` ≠ `string+int`, but
int+int is not allowed, i.e. you can always uniquely ask “Does it
contain an `int`?” Without ambiguity about *which* `int`.
What is your take on qualifiers? Is `int+const(int)` allowed
and/or the same as `int`?
Do your sum types nest or are they flat? As an example, D’s alias
sequences are flat: `AliasSeq!(a, AliasSeq!(b, c), d)` =
`AliasSeq!(a, b, c, d)`. A sum type implementation can make
`int+(char+string)+double` be `int+char+string+double` or keep
the nesting. As alias sequences show, flattening is not that bad
and if not desired, can be mitigated using wrappers.
Does it support the empty sum? It would naturally be a bottom
type.
Does a unary sum exist? It would naturally be equivalent to the
only type argument.
You had to make these decisions (even if unaware of the options).
What did you decide for Neat?
More information about the Digitalmars-d
mailing list