• barsoap
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    I was thinking along the lines of “you can’t easily get at the wrapped type”. To get at b instead of Maybe b you need to either use do-notation or lambdas (which do-notation is supposed to eliminate because they’re awkward in a monadic context) whereas Rust will gladly hand you that b in the middle of an expression, and doesn’t force you to name the point.

    Or to give a concrete example, if foo()? {...} is rather awkward in Haskell, you end up writing things like

    foo x y = bar >>= baz x y
      where
        baz x y True = x
        baz x y False = y
    

    , though of course baz is completely generic and can be factored out. I think I called it “cap” in my Haskell days, for “consequent-alternative-predicate”.

    Flattening Functors and Monads syntax-wise is neat but it’s not getting you all the way. But it’s the Haskell way: Instead of macros, use tons upon tons of trivial functions :)