Hacker News new | ask | show | jobs
by masklinn 717 days ago
Yes.

> I can't tell if I'm amazed or terrified.

The rule is very simple and obvious, and the compiler will yell at you if you get it wrong.

It's also very useful and even critical of how expression-oriented the language is: an `if/else` or a match statement must typecheck, all branches have to have the same type. It's obvious if you're using it as an expression, but it doesn't go away if you're using it for the side-effect (as an imperative conditional/switch) and then things can get more dicey as the expressions in each branch can have different types. `;` solves that by making every branch `()`-valued.

1 comments

Okay, this is really neat design. I went to check whether if..else works in an expression context and it does:

    fn five() -> i32 {
        let a = if (true) { 3 } else { 6 };
        return a + 2;
    }
Pure fun!
Ya if you want fun match/case also works like that.

And though for abs while don’t (they always return ()) `loop` itself does, you can `break` with a value and that’s what comes out the loop.