News for hackers. Stuff that matters.
Re:Problems of C, and how Zig addresses them by justinpombrio on Monday July 03, 2023 @06:05PM (#36579426)
How would the language require it to be numerical? For example, if you're defining complex numbers in a library, what would the compiler be checking about your ComplexNumber type before allowing you to define `+` for it?
Re:Problems of C, and how Zig addresses them by naasking on Monday July 03, 2023 @11:26PM (#36581828)
A few ways. The compiler could enforce commutativity, associativity and other properties of those operators.

Another possible route is to require that all types contained within the exported types are also numerical, or have some specific set of operators defined.

Re:Problems of C, and how Zig addresses them by SkiFire13 on Tuesday July 04, 2023 @02:23AM (#36582911)
Do you mean at the type level or also for the operational semantics? In the latter case it's undecidable.

Also, you mentioned matrices in the previous comment, but multiplication between matrices is not commutative.

Re:Problems of C, and how Zig addresses them by naasking on Tuesday July 04, 2023 @09:04AM (#36586134)
It's undecidable if the language used to define operators is sufficiently expressive. Even simple syntactic constraints would work well enough for most scenarios, like "operators may only be defined by an expression containing other operators".

New types also don't have to inherit the properties of the operators they use.

In any case, my point was that there are multiple avenues to explore in providing operators in a way that don't compromise the compiler's ability to optimize numerical code.