3 ms·
> Statically typed languages like Haskell and Rust require > the programmer to list all possible cases when matching > on a value. This isn't a consequen
by kibwen 13y ago
> Statically typed languages like Haskell and Rust require
> the programmer to list all possible cases when matching
> on a value.
This isn't a consequence of static vs. dynamic, it's just a question of philosophy. In fact, Rust didn't use to require you exhaustively list out all cases, though it does today in order to help catch errors at compile-time rather than at runtime.
I should also mention that if yo don't want to list out all variants, that's easily done by using the _ pattern (the "ignore this" pattern):
match some_direction {
East => print("You're going east!"),
_ => print("You're going in some direction that isn't east!")
}
- alco 13y agoWhat I mean is that it's not possible in a dynamically typed language to enforce at compile time enumeration of all possible cases for a variable, the type of which will be known at run time.