3 ms·
Arbitrary subranges of int types were available in Ada for over 40 years via static enforcement via Spark and compilers were able to optimize them nicely. For
by fpoling 25d ago
Arbitrary subranges of int types were available in Ada for over 40 years via static enforcement via Spark and compilers were able to optimize them nicely.
For a system language I wish Rust would support such things rather than coming with NonZero hacks.
- steveklabnik 25d agoThis is called "pattern types" in Rust land, as your parent mentioned, and is exactly the kind of work being talked about. NonZero isn't a hack: it's an example of a common pattern. If pattern types were available today, you'd still want NonZero, as an example of a pretty standard pattern. The idea is, as always: prove out the specific version, then generalize.
- BoingBoomTschak 25d agoCan it do holes like this? (typep 3 '(or (integer 0 10) (integer 50 100)));; => T
- steveklabnik 25d agoYou can use a "subtype predicate" for this: https://learn.adacore.com/courses/Ada_For_The_CPP_Java_Developer/chapters/05_Type_System.html#generalized-type-contracts-subtype-predicates https://learn.adacore.com/courses/Ada_For_The_CPP_Java_Devel...
- BoingBoomTschak 25d agoMight be less efficient, no? At least in CL (https://www.lispworks.com/documentation/HyperSpec/Body/t_satisf.htm https://www.lispworks.com/documentation/HyperSpec/Body/t_sat...) this is the case, that static type analysis isn't clever enough to work with predicate based types.
- steveklabnik 25d agoI don't know enough about the details to speak to it.