Re:Fast integer overflow detection (2012)
by eric_bullington on Sunday December 14, 2014 @05:59PM
(#8749898)
I'm pretty sure Ada's ranged integer is tested dynamically, not statically. It's still a cool language feature. To get a static detection of integer overflow, I think that you need to use some variation of dependent typing.
So it's possible in Liquid Haskell. And of course, it's easily done in dependent-typed languages like Agda, Coq, and Idris.
Edit: I had earlier written Nim has this static range checking capability, but it looks like it also uses a runtime check.
Re:Fast integer overflow detection (2012)
by danbruc on Sunday December 14, 2014 @05:34PM
(#8749819)
Interoperability may be a factor. Everything that enters your world will tell you nothing about the possible ranges and you pretty quickly have to assume the worst case everywhere or add range limiting assertion early. It still sounds like a good idea but maybe it's harder to do than it seems.
Range checking early doesn't strike me as a bad thing at all.
Well, Ada[0] had ranged integer types which allowed the compiler to determine whether overflow can occur statically. I don't know why modern languages like C#, Java, Go and Rust don't do this instead of taking the performance hit... in general no JIT will save you, and it's useful for things like formatted I/O and parsing as well
[0] https://en.wikipedia.org/wiki/Ada_%28programming_language%29...