4 ms·
I'm sure I'm just missing something, but I'm struggling to come up with a reasonable case where you couldn't just have a and b be different types and provide an
by ajanuary 15y ago
I'm sure I'm just missing something, but I'm struggling to come up with a reasonable case where you couldn't just have a and b be different types and provide an operator for typeof a - typeof b but not typeof b - typeof a (or vice-versa).
Of course, that would upset Joel on account of not knowing what - did without knowing the types.
- masklinn 15y agoDepends what you mean by "reasonable" I'm guessing. Manually encoding a semantic analysis would have a very high overhead, and you might be able to do it via dependent types instead (not sure though, they tend to hurt my brain when I try to actually understand them), but I don't think they're considered practical (yet).
- vilya 15y agoJust because you can, doesn't mean you should. :-) Forcing a and b to be different types could cause a different problem - maybe a worse one, depending on how many subtractions your code requires.
- JadeNB 15y agoIt's maybe not very realistic, but you'd have trouble with this approach if you were trying to code the distance function `(a, b) \mapsto |a - b|` in a language that didn't have an absolute value.