News for hackers. Stuff that matters.
Re:Is your programming language unreasonable? (2015) by anw on Saturday October 10, 2020 @12:41PM (#24740117)
> Do most (or any) languages in which people take this approach actually enforce handling of all cases?

I'm not familiar with most languages, but I can state that Rust requires matching sum types to cover all possible variants. For example:

    enum Animal {
        Dog,
        Cat,
        Pigeon
    }
    let pet = Animal::Dog;
    let sound = match pet {
        Animal::Dog => String::from("ouaf"),
        Animal::Cat => String::from("miaou")
    };
This would not compile, because you've forgotten to cover the pigeon. You would need to either add one of the two lines below:

    Animal::Pigeon => String::from("rou rou")
or

    _ => String::from("eeeeeeeeeeeei")
The last line is a catch all, which would cover anything not checked for explicitly.

There are no comments on this comment yet.