
Zeljko Vrba wrote:
Actually, I think I could simplify my requirements a bit:
I strongly agree with your proposal, and pretty much everything in your post. I would also like the possibility to explicitly state the lower- and upper-bound in the type and the possibility to use a dynamic integer (without any bounds), should the need arise. In my opinion, the ideal solution would be to have only one int type in the language, which would conceptually have no bounds. Convenient sub-types (like uint) would be defined which would enforce type-invariants (like: value >= 0). The programmer may also define his own sub-types. All int-types would be compatible, however, and behave correctly in a mathematical sense. If an operation between two integers overflows, an assertion failure would arise. This is clearly not possible for C++. But I'm designing a programming language where integers work this way. The hope is that the bounds of a plain int may be found (formally proved) at compile-time, so it can be cleanly mapped to a hardware-int without any runtime overhead. If the programmer specifies bounds, they are either proved correct at compile-time or enforced at run-time. In all other cases, a dynamic int is used. This should completely eliminate unexpected runtime overflow. I'm also thinking of making int itself a subtype of a bit-array, which would take care of bit-shift operations. But I'm not really sure how that would work yet for all integers, since I would like to make the behavior hardware independent and predictable. -- Michiel Helvensteijn