• barsoap@lemm.ee
    ·
    1 year ago

    The exception handling question mark, spelled ? and abbreviated and pronounced eh?, is a half-arsed copy of monadic error handling. Rust devs really wanted the syntax without introducing HKTs, and admittedly you can't do foo()?.bar()?.baz()? in Haskell so it's only theoretical purity which is half-arsed, not ergonomics.

    • m_f@midwest.social
      ·
      1 year ago

      It's not a half-arsed copy, it's borrowing a limited subset of HKT for a language with very different goals. Haskell can afford a lot of luxuries that Rust can't.

      • barsoap@lemm.ee
        ·
        1 year ago

        It's a specialised syntax transformation that has nothing to do with HKTs, or the type system in general. Also HKTs aren't off the table it's just that their theory isn't exactly trivial in face of the rest of Rust's type system but we already have GATs.

        It actually wouldn't be hard writing a macro implementing do-notation that desugars to and_then calls on a particular type to get some kind of generic code (though of course monomorphised), but of course that would be circumventing the type system.

        Anyhow my point stands that how Rust currently does it is imitating all that Haskell goodness on a practical everyday coding level but without having (yet) to solve the hard problem of how to do it without special-cased syntax sugar. With proper monads we e.g. wouldn't need to have separate syntax for async and ?

    • arc@lemm.ee
      ·
      1 year ago

      You can say it's half-arsed if you like, but it's still vastly more convenient to write than if err != nil all over the place