3 ms·
The real issue is the lack of dependent types in Haskell (and unfortunately Rust and all languages with a vast ecosystem). With dependent types, you can just i
by devit 6y ago
The real issue is the lack of dependent types in Haskell (and unfortunately Rust and all languages with a vast ecosystem).
With dependent types, you can just include a type-level proof that x <= 5 in the integer wrapper type, which then allows to statically check that the default case in the match is impossible.
A newtype including such a dependently-typed proof is the correct solution to this problem, since it can be generalized to any range, unlike the enum with 5 variants.
- rowanG077 6y agoIt's possible to do this in haskell but it's quite clunky.