Login
You're viewing the slime.global public feed.
  • Oct 19, 2026, 4:33 PM

    @mcc The most educational approach is probably to do it all three ways:
    1. normal recursive techniques
    2. IO monad imperative program
    3. Roll your own monad encapsulating the boilerplate from (1) that hopefully shows that the structure from (2) is not tied to IO, but to accumulating some state in the background and having some kind of unwind opration.

    Folks will tell you to use monad transformers or effect frameworks. But I don't think that's nearly as educational as doing (1) and (3).

    💬 1🔄 0⭐ 0

Replies

  • Oct 19, 2026, 4:36 PM

    @mcc Monad transformers, effect handler libraries etc all solve the "I'm tired of writing boilerplate monads by hand" problem that you don't have yet. After like the 5th or 6th time you have to do the same return and bind implementation, it might be worth a look. But tbh it's diminishing returns and just endless endless navel-gazing

    💬 0🔄 0⭐ 0
  • Oct 19, 2026, 4:39 PM

    @lambdageek It is good thinking! One thing of note is that I need some kind of pause/resume feature ANYWAY, so that if one of my runs takes "too long" mastodon.social/@mcc/117468548 I can come back to it later.

    One option would be to write the "normal recursive"/OCaml version first because I'm certain i can finish it within my time limit, and I can return latre and do the more-complex version without time pressure and AFTER reading, like, a book or three about this.

    💬 1🔄 0⭐ 0
  • Oct 19, 2026, 4:49 PM

    @mcc Good news: coroutines are also a monad.
    Bad news: I'm not sure there's a good way to arrive at the coroutines monad in a natural way from how you'd write the "normally", unless you just write all your code in continuation-passing style by default.

    Also in this case doing the "IO monad imperative program" version is probably going to be a dead end because I think refactoring it out into a pause/resume version is not going to be very natural.

    💬 1🔄 0⭐ 0
  • Oct 19, 2026, 4:54 PM

    @lambdageek "coroutines are also a monad"

    Oh, I am *so* happy to hear that.

    And I think I was unclear, the halt/resume version is something I believe I can implement with Either. Like, I can implement that without even changing the program much using only features that exist in OCaml.

    💬 1🔄 0⭐ 0
  • Oct 19, 2026, 4:55 PM

    @lambdageek Hm, I wonder if anyone in functional space has implemented the Amb monad with multithreading.

    💬 0🔄 0⭐ 0