News for hackers. Stuff that matters.
Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f... by mgaunard on Sunday May 05, 2024 @10:05AM (#40264996)
std optional is based on boost optional which was written in 2003 before any sort of lambdas made monadic operations usable.

The main concern with that component was ensuring we can allocate stack storage for an object that may or may not be initialized.

The reference is easily achievable by using T* so is of minimal value, but also poses some more semantic problems since a reference is not copyable while an optional is.

Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f... by tialaramex on Sunday May 05, 2024 @09:28PM (#40270273)
I actually don't care that much about the monadic functions.

For me the important use case is pattern matching, which C++ doesn't yet have. Pattern matching really changes how you see the entire language.

Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f... by mgaunard on Monday May 06, 2024 @12:14AM (#40271087)
C++ has pattern matching through overloading.
Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f... by tialaramex on Tuesday May 07, 2024 @07:29PM (#40292704)
How do you figure?
Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f... by mgaunard on Wednesday May 08, 2024 @03:15AM (#40295208)
I don't understand the question.

Here is the first example I found on Google if that helps you understand.

    std::variant<Fluid, LightItem, HeavyItem, FragileItem> package;

    std::visit(overload{
        [](Fluid& )       { std::cout << "fluid\n"; },
        [](LightItem& )   { std::cout << "light item\n"; },
        [](HeavyItem& )   { std::cout << "heavy item\n"; },
        [](FragileItem& ) { std::cout << "fragile\n"; }
    }, package);
Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f... by tialaramex on Thursday May 09, 2024 @10:35AM (#40308651)
But that's not really even a pattern match? Here's what a pattern match looks like: [This is from day 10 of last year's Advent of Code.]

            match (state, pipe) {
                (State::None, Pipe::Ground) => {
                    if inside {
                        n += 1;
                    }
                }
                (State::None, Pipe::Vert) => {
                    inside = !inside;
                }
                (State::None, Pipe::Se) => {
                    state = State::South;
                }
                (State::None, Pipe::Ne) => {
                    state = State::North;
                }

                // Horizontal lines make no difference to anything
                (State::North | State::South, Pipe::Horiz) => {}

                // U-turns
                (State::South, Pipe::Sw) | (State::North, Pipe::Nw) => {
                    state = State::None;
                }

                // Form a vertical line
                (State::South, Pipe::Nw) | (State::North, Pipe::Sw) => {
                    inside = !inside;
                    state = State::None;
                }

                _ => {
                    panic!("Unexpected sequence {state:?} {pipe:?}");
                }
            }
Re:Rusty.hpp: A Borrow Checker and Memory Ownership System f... by mgaunard on Friday May 10, 2024 @05:15AM (#40316863)
This is the exact same thing except you're visiting two arguments at a time.

Guess what, the same syntax I gave supports exactly that as well.