News for hackers. Stuff that matters.
Re:Don't Be Afraid of Types by josephg on Saturday March 22, 2025 @08:58AM (#43445419)
You could do it with asserts or as a wrapped type, but both of those approaches are only checked at runtime. That means you don’t get runtime errors instead of compiler errors. It also limits the compiler’s ability to take advantage of the constraint to optimise. Also asserts need to be added everywhere - by both you and the compiler. And wrapped types are annoying to use since you lose access to all the standard arithmetic operators.

It would be better if the type system could encode types like this directly. Better for ergonomics and better for optimisation.

There are no comments on this comment yet.