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).

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.

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.

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.

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?)

canlearn monads. It certainly takes time, though, and unlike many things in this field, there are no shortcuts. As in mathematics, you reallydohave to learn the conceptual infrastructure (e.g. type classes) first, especially if you want tomotivatethe concept (which is really the only way to make it stick, in my experience).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.

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

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.

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

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.