I think it would be nice to get some concept of abs which works for not only Int and Number, but also more exotic numeric types, like Rational, Complex, and even Quaternion (when we eventually implement it ;).
Given that we (well, I) want this to work for numeric types which don't have total orders (such as Complex), I thought a good starting point would be to take laws from https://en.wikipedia.org/wiki/Absolute_value but remove all those to do with ordering, so:
class Semiring a <= Absolute a where
abs :: a -> a
Laws:
- Positive-definiteness:
abs x == zero iff x == zero
- Multiplicativeness:
abs (x * y) == abs x * abs y
- Idempotence:
abs (abs x) == abs x
We could add more laws by making the constraint a bit stronger, to Ring if we want those that mention subtraction, or maybe even EuclideanRing if we want those that mention division. But the above seems a good starting point, I think.
I think it would be nice to get some concept of
abswhich works for not onlyIntandNumber, but also more exotic numeric types, likeRational,Complex, and evenQuaternion(when we eventually implement it ;).Given that we (well, I) want this to work for numeric types which don't have total orders (such as
Complex), I thought a good starting point would be to take laws from https://en.wikipedia.org/wiki/Absolute_value but remove all those to do with ordering, so:Laws:
abs x == zero iff x == zeroabs (x * y) == abs x * abs yabs (abs x) == abs xWe could add more laws by making the constraint a bit stronger, to
Ringif we want those that mention subtraction, or maybe evenEuclideanRingif we want those that mention division. But the above seems a good starting point, I think.