3 ms·
Your intuition about the benefits of pure functions & immutability are spot-on, and I think that any proponent of monads would agree that these are fundamentall
by gmfawcett 9y ago
Your intuition about the benefits of pure functions & immutability are spot-on, and I think that any proponent of monads would agree that these are fundamentally more important concepts than monads themselves. (Many of the ways that people use monads would break, or lose their point, if the data they operated over could be mutated outside of the monadic context.)
You can get an awfully long way with immutable data structures without involving monads. There are plenty of languages that give priority to immutable data, but don't have monads in any inherent way: Prolog, Erlang, Ocaml, and Scheme (to a slightly lesser extent) all come to mind.
- zmonx 9y agoProlog has definite clause grammars (DCGs), which are very similar to monads. You can think of a DCG as giving you two implicit arguments, which you can use to express concatenations and in fact arbitrary relations between states. There are also ways to access these implicit arguments, which are similar to the corresponding constructs in Haskell. DCGs are a very important feature of Prolog. They are frequently used for parsing and state transformation tasks. Like monads in Haskell, DCGs often make working with immutable data much more convenient, because you can make the more uninteresting parts of your code implicit. Other logic programming languages like Mercury also support DCGs.
- gmfawcett 9y agoIt never occurred to me that there were similarities between DCGs and monads, but that's an interesting argument. Thank you for this!