Standardize base types for metaprogramming

Dukc ajieskola at gmail.com
Wed Apr 3 19:14:01 UTC 2024


On Thursday, 29 February 2024 at 21:16:32 UTC, monkyyy wrote:
> 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

I have some gripes with this list. For example, `""` is *not* a 
good "zero" value. If we define one, it should be defined only 
for types that have a literal zero value. That means ints and 
floats and other numeric types, nothing else.

I'm more sympathetic to the general notion though. We could well 
have a property called somthing like `.validDefault` that would 
be 0 for floats, `'\0'` or `' '` as opposed to `'\xff'` for 
`char`s and so on. Maybe it should be undefined for classes 
though. There's not really a good `.validDefault` value for 
`object`, as a null reference is hardly any more valid than NaNs 
are. Same for pointers.

The thing with metaprogramming is, you really can't be fully 
generic no matter the language rules. Even if you had a nice 
valid value for every built-in type, people will want to define 
types there can be no good values for. An extreme example is the 
bottom type. It can only ever be:
1. A type system breaking unsafe value.
2. Never instantiated in actual execution flow.


More information about the dip.ideas mailing list