Algebraic Effects for the Rest of Us

(overreacted.io)

13 points | by satvikpendem 3 days ago

4 comments

  • Trung0246 4 minutes ago
    For some funsie here's my fully working delimited continuation in C with effect handler example: https://godbolt.org/z/3ehehvo6E

    No ASM involved so technically portable (although it depends on built-in).

  • satvikpendem 10 minutes ago
    Oh neat, I'm in the second chance pool.

    I submitted this because I've been getting really interested in effect systems, especially now that OCaml 5 has a working production quality example they'd been iterating on for years prior. I wanted to see what it'd look like in Rust too so maybe one day we can get rid of async function coloring, and with OxCaml by Jane Street maybe we could see how that would look in practice.

    Another reason for submitting this is that React actually has a quite robust effect system, that people don't necessarily realize they're using one every day if they use hooks.

  • HeyImAlex 32 minutes ago
    Do effect systems actually avoid colored functions? Don’t most typed effect systems require the used effects in the signature?
    • codebje 13 minutes ago
      When you need to use an effect, you need it in the type. If you directly call a function using some other effect, it propagates into your function. So far, so colourful.

      But you can have generic effects. Your arguments and return type can specify "any effect", indicating your function can use a type with any effect safely, or can be used in any effect context safely.

      Passing an async value to a function doesn't mean that function must now also be an async function. It can be a "for all effects, do the thing" function. The code duplication problem is gone.

    • mrkeen 8 minutes ago
      No, they are function colouring. That's the point.

      Someone writes a post lamenting red and blue functions, and everyone eats it up.

      Substitute colour for something meaningful and the idea becomes idiotic.

      "Top level function declares that it is non-blocking, but when I try to call a small blocking function from it, I have to change the declaration to blocking???"

      Yes, yes you do.

      Total functions can't call non-total functions.

      Deterministic functions can't call nondeterministic functions.

      Non-IO functions can't call IO functions.

  • epolanski 6 minutes ago
    Everything he lists is solved by effect-ts [1] bar, obviously, the language support.

    I've been using it from 5 years.

    The amount of features in effect is basically endless.

    [1] https://effect.website/