3 ms·
There are no enums in Erlang and Elixir. If you have a case expression and there is no match with the given value, you'll get a run time error. This is delibera
by alco 12y ago
There are no enums in Erlang and Elixir. If you have a case expression and there is no match with the given value, you'll get a run time error. This is deliberate and is part of the general approach to error handling in those languages.
Statically typed languages like Haskell and Rust require the programmer to list all possible cases when matching on a value.
- IsTom 12y agoHaskell doesn't require you to do that by default. There is a warning flag for that, but in general language is okay with defining partial functions, more so than most languages (because laziness lets you cheat death).
- kibwen 12y 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 12y 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.