Names and design of partial sumtypes
monkyyy
crazymonkyyy at gmail.com
Sat Feb 15 19:49:59 UTC 2025
I think full sumtypes are probably usually overkill and I rarely
use it; but I have some lib ideas that need... something
```d
struct shape{
int w,h;
bool isCircle()=>h==-1;
bool isSquare()=>w==h;
bool isRect()=>h!=-1 && w!=h;
}
void drawCircle(shape s){
assert(s.isCircle)
...
```
Classification could be pulled out from tag and it being a full
union in the above example.
Radix sorts classify using a user defined function to then index
an array of pointers to make a copy
fizzbuzz using ranges is kinda tricky, despite being
computationally trivial, maintaining the control flow from
classification while having access to the data is hard
etc.
----
so api wise...
classify: returns an int from the value
classmax: defines that max value classify may return(enum)
match: calls classify, swizzles the value to a collection of
lamdas
etc.
what preexisting code plays with such ideas and how do they name
their things?
More information about the Digitalmars-d-learn
mailing list