1. 13

  2. 5

    I taught a short course in Haskell last summer in Chicago. My experience was that monads aren’t “hard” to learn in the sense that there is a high failure rate. Most competent programmers (all?) can learn monads. It certainly takes time, though, and unlike many things in this field, there are no shortcuts. As in mathematics, you really do have to learn the conceptual infrastructure (e.g. type classes) first, especially if you want to motivate the concept (which is really the only way to make it stick, in my experience).

    1. 5

      Monads aren’t that hard to learn. However, to get almost any non trivial stuff done, monad transformers are necessary, and that becomes complicated very fast.

      1. 3

        Monad transformers really aren’t much more complicated than monads. They, like monads, just take some time to absorb.

        1. 2

          I think the main problem with people talking about monads is the people who understand it don’t enjoy talking in non-rigorous language. What happens is that because there is a lack of good explanation for those that don’t know the terms, then those who barely understand it feel a need to try to explain it which is mostly harmful. You can learn what they are and how to reason about them without the underlying mathematical theory, and those saying otherwise are making perfect the enemy of the good.

          1. 2

            But for what? What is the gain from designing a giant stack of transformers?

            1. 3

              Monad transformers are one option to control possible program effects using the type system. They work by allowing the combination of multiple monads via transformer types associated with particular monads. For example, if you have a system that needs to both perform IO and read from some sort of global configuration (held in a type Config, we’ll say), you would want some way to combine the IO and Reader monads together. This is accomplished with ReaderT, resulting in ReaderT Config IO (), where Config is the thing to read from, IO is the inner monad, and () is the return type. There are a few different libraries that exist to make using these transformers easier.

              Monad transformers are not the only option for this sort of problem. There are other options like Extensible Effects and Freer Monads which provide different ergonomics and may be preferable depending on the situation.