logoalt Hacker News

hmrylast Tuesday at 6:31 PM0 repliesview on HN

> Rust's result type is just syntactic sugar around the multiple return value approach

That's really not true. Multiple return values means you always need to return some return value and some error value, even if they are dummy values (like nil). While a result type / sum type genuinely only contains one branch, not the other.

If you had a language that didn't have nil, it would genuinely be impossible to emulate sum type like behavior on top of multiple return values. It serves as an escape hatch, to create a value of some type when you don't actually have a meaningful value to give.

std::variant / std::expected / std::optional aren't syntactic sugar for std::pair either.