| You know, I wasn't entirely sure, but after researching it, the "let" form in Clojure is a monad. Monads are something that I keep trying to learn, but for whatever reason, the info just won't stick. After decades of doing this, my brain automatically seeks out the laziest way of doing things (while still being deterministic, testable, automatable, etc). Monads seem to be a very "hands on" way of doing FP programming, which to me defeats the whole purpose. I would probably only use them in an emergency, or to port existing functionality from an imperative language, like I mentioned. These are the first 3 links that popped up for my Google context: https://github.com/khinsen/monads-in-clojure/blob/master/PAR... https://cuddly-octo-palm-tree.com/posts/2021-10-03-monads-cl... https://functionalhuman.medium.com/functional-programing-wit... Aspects of this do look eerily similar to async (promises/futures), like maybe monads could be implemented via nullable/optional values. I think of promises as polling a nonblocking stream result until the point in the code where the result is needed, and then blocking until the promise is fulfilled. Which is basically fork/join of threads of execution, with different syntax. The articles mention that Haskell has syntactic support (I assume sugar) for monads. I'm nearly always against syntactic sugar and domain-specific languages (DSL) though, because they obfuscate what's really going on and double the mental load by creating two or more ways of doing the same thing. It would be fine if languages let us instantly reformat the code by transpiling with various languages features toggled (like Go's gofmt but more than just whitespace) so we could see what the syntactic sugar is doing. But nobody does anything like that, which is why I'm skeptical. I feel like monads are one way of approaching mutability, but there are others. I'm curious how shadowing variables and even stuff like Rust's borrow checker plays into this. Like why couldn't we have a pure FP language with only immutable data and no borrow checker? That executes in its entirety when new data arrives on a queue like STDIN or a queue like STDOUT has a slot available, otherwise it blocks? I guess fundamentally, I don't understand why a spreadsheet needs scripting (written in mutable languages of all things!) or FP needs monads. Another insight is that a monad isn't really an optional value, it's a way of executing multiple potential branches of logic. Which is similar to electrical circuits or switching at railway stations. This happens in shaders when both sides of a branch are executed, but only the outcome that matches the result of the branch is kept: https://fsharpforfunandprofit.com/rop/ https://vimeo.com/113707214 |