Why are overflow checks not performed on unsigned integers? Doesn't it probably make the result inaccurate?
For example
echo uint.high + 1
outputs 0, even if the overflow can be detected at the compile-time.
Also, the checks seem to always be performed on signed integers, even those cannot overflow (e.g. the iteration variable in a for loop).
From a computer algebra point of view, I still find uint more interesting than Natural types. There are some algorithms for reduction modulo p, where you actually want the overflow to happen. You can sometimes detect it mathematically speaking and correct the overflow for higher performance. I am thinking of the reduction by the block-overflow algorithm in Jean-Guillaume Dumas, 2004, "Efficient dot product over Word-Size Finite Fields", for reference.
I am also reticent to use Natural types, since you can not convert back and forth with integers and most functions are written for integers in libraries. To me, this additional type add «color» to the functions just like async/await construct does in Javascript
To write functions independently from these type choice, we can use generics in the function definition. When functions we want to use come from external/standard library, we do not have the hand on it, which is frustrating, since it basically forces us to rewrite functions to accept Naturals.
Please correct me if I am wrong, I am not the best developer of the Nim community. I hope in fact that Naturals are not so coercive as I think.
To me, this additional type add «color» to the functions just like async/await construct does in Javascript
Every type distinction introduces these "colors". So it doesn't actually mean anything to complain about "colored" functions.
I am also reticent to use Natural types, since you can not convert back and forth with integers and most functions are written for integers in libraries.
Not true?
let a: int = 1
let b: Natural = a
let c: int = b
echo (a, b, c)
The problem might be that the base type of Natural is int and not compatible with other sized integer types.