3 ms·
> Ada has always had integer ranges. Dependent types include integer ranges, but integer ranges aren't necessarily dependent types. I was under the impression
by HumanDrivenDev 9y ago
> Ada has always had integer ranges. Dependent types include integer ranges, but integer ranges aren't necessarily dependent types.
I was under the impression that Adas integer ranges were checked at runtime, like contracts. Is that not the case?
- DonaldFisk 9y agoThat's correct, it's a run-time check. According to https://en.wikibooks.org/wiki/Ada_Programming/Types/range https://en.wikibooks.org/wiki/Ada_Programming/Types/range A range is a signed integer value which ranges from a First to a last Last. It is defined as range First .. Last When a value is assigned to an object with such a range constraint, the value is checked for validity and Constraint_Error exception is raised when the value is not within First to Last.
- HumanDrivenDev 9y agoRight. I said dependent types would allow you to statically declare integer ranges, as is my understanding. It's interesting to me how Ada takes the approach of blending types and run time contracts. In most languages it would be two different things - a function that takes int, then a contract or assert that handles the value.
- DonaldFisk 9y agoThey allow you to statically declare integer ranges (as well as other things), even if their bounds are unknown until run-time, and without requiring a run-time type check.
- mjn 9y agoSome Lisp implementations (like SBCL) also do that blending, although they can statically catch some integer range violations too. For example if you declare a variable to be an (integer 50 100) and try to assign a literal 30 to it, you'll get a compile-time warning in SBCL: ; Constant 30 conflicts with its asserted type (INTEGER 50 100). But in many other cases it'll generate a runtime check instead, because the static type checking is basically best-effort.