3 ms·
It makes you long for a dependently typed language where you really and truly can switch on decidable relations like "compare". For example, I have some Agda c
by Smaug123 7y ago
It makes you long for a dependently typed language where you really and truly can switch on decidable relations like "compare".
For example, I have some Agda code (totally unreadable to anyone who didn't write it, i.e. anyone who isn't me) where I switch on whether a+1 is less than, equal to, or greater than x+1, as part of the inductive step in an implementation of the division algorithm, rendering a number into a quotient and a remainder on division by another number. The type system guarantees that I haven't missed any cases. (https://github.com/Smaug123/agdaproofs/blob/9e22ba78f5446ce7272ee342affdfafa2ae189ae/PrimeNumbers.agda#L76 https://github.com/Smaug123/agdaproofs/blob/9e22ba78f5446ce7...)
- masklinn 7y agoTBF for cases which are not overly complex like your case you just need the right enums and functions e.g. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=898a93af528fd3d164b166dbea0436e6 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- pwdisswordfish2 7y agoSwitching on a comparison result has nothing to do with dependent typing. You can do this in Rust, where dependent typing has barely left the planning stages, last I checked.