News for hackers. Stuff that matters.
Re:Why Rust helps even if you have to use a lot of `unsafe` by soulbadguy on Wednesday August 02, 2023 @12:01PM (#36972711)
I love sum types, and i find it very hard to work without them when i am in C++.

However your examples i don't think are particularly convincing.

The examples you gave can mostly be done with std::variant<> and are simply examples are unions. (Result == std::expected)

In term of non nullable smart pointer, it would be easy to enforce the the non nullability in the constructor, and have the same ergonomy as Option<Box<T>>. In fact you can do something like std::expected<std::reference<T>> but why would you instead of just std::unique_ptr and handle the nullable case.

What makes sum type powerfull is to have full Algebraic DataType (tags + sum types + product types) + pattern matching + good compiler errors.

There are no comments on this comment yet.