Hacker News new | past | comments | ask | show | jobs | submit login

If I was designing a new language I'd rather specify integer types by their range of expected values, and let the storage size be an implementation detail.

(not sure if this would ever come up, but if a variable had eg values 1000-1003, then technically you could optimize it to a 4-bit value.)




Depending on what your language is for you probably want both.

WUFFS type base.u8[0 ..= 42] is a type which fits in one byte but only has values zero through 42 inclusive, and it's a different type from base.u32[0 ..= 42] because that one takes four bytes.

Rust cares about this stuff to some extent but only internally, for types with a "niche" where it can squirrel away the None case of Option in an invalid value without needing more space. e.g. Rust's optional pointer is the same size as a traditional C-style pointer, because NULL isn't a valid pointer value so that means None, and Rust's optional NonZeroU64 is the same size as a u64 (64-bits) because zero isn't valid so that means None.


Ada is what you're looking for!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: