Standardize base types for metaprogramming

monkyyy crazymonkyyy at gmail.com
Thu Feb 29 21:16:32 UTC 2024


Inside 5 layers of metaprogramming a mild inconsistency can break 
everything and require nested trait hell static ifs to fix. The 
base types just don't offer a consistent interface.

`int.init!=float.init` but what are you supposed to do besides 
when you write a function header such as `foo(T)(T a, T b=T.init)`

Also user types need to use op overloads where theres no drop in 
replacement for base types, I can't just use 
opCmp()=>child.opCmp; I have to detect if its a base type and 
handle.

In practice there are three cases for even conceptually simple 
composite type, user types, the usual base type behavior, a weird 
edge case base type; don't do that.

I suggest extending all base types with at least 5 values(with 
example int,float,string):

1. zero: 0, 0.0., ""
2. invalid: max-1, nan, "ERROR"
3. onevalue: 1, 1.0, "1"
4. negative_value: -1 (signed) max (unsigned), -1, "WARNING"
5. min: .min, .min_normal, ""

And then define element op overloads(such as opCmp), toString, 
toHash for each base type


More information about the dip.ideas mailing list