I hate the way monads in general are talked about in the Haskell community (I also do not like the language for other algebraic terms). In particular, it is common to say 'data type X is a monad'. This statement is completely nonsensical. A monad is a thing along with some operations. Haskell data is a concrete description of how to store a thing. By itself, a piece of data has no operations associated with it. There is no way a particular data type could be a monad, since a data type is just a thing.
The proper terminology is 'X forms a monad along with these functions' or 'X has an instance for the Monad type class' (this is different, because the monad type class allows for a subset of monads, not general monads). I am on a personal mission to rid the Haskell world of sloppy language because it confuses beginners, in my opinion. For a long time, I thought monads were a thing. Then I realized they're just an algebraic structure, like groups or rings.
When we say things like 'monads don't compose' it makes it seem like there is some deficiency in the idea of a monad that makes them not compose, rather than a realization that monad composition results in zero or more ways to combine two arbitrary monads. Thinking just the former makes you wonder if monads ought to be fixed. Realizing the latter means you realize that the lack of a fix indicates that putting two monads together can accomplish a variety of tasks, only one of which is likely suited to your use case.
I think the reason for this is that in Haskell we model algebraic structures using typeclasses, which are dispatched by type. So we say “X is a monoid, with mempty and mappend defined as follows”:
instance Monoid X where
mempty = …
mappend = …
Instead of “X, emptyX, and appendX form a monoid”: instance Monoid X emptyX appendX
emptyX = …
appendX = …
This leads to what I call the “newtype hack” for distinguishing different monoids (resp. monads, &c.) on the same underlying type.Shockingly, our understanding of monads and monad transformers has advanced in the last 23 years.
@danharaj, of course!
At least enough that when someone says "MTs exist to compose monads", to understand it as "MTs are used in Haskell programs to compose monadic effects".
I see what you mean.
You are right - the concept of Monad Transformers exist independent of the fact that monads don't compose.
What I meant was that MTs exist in Haskell programs because Monads don't compose. Of course, there probably exists a Haskell program where this is not the case, but I am certain MTs are largely used in Haskell because Monads don't compose.
BTW, the grandparent is not the first to coin "MTs are .. use(d) to make monads compose" usage. The late Paul Hudak et al writes in [1] that:
Notice the usage Steele proposed pseudomonads as a way to compose monads. So this usage has been established in the Haskell community at least from 1995. Why are you, presumably a Haskell programmer, surprised when someone repeated that usage in 2018 on an internet forum?[1]: Monad Transformers and Modular Interpreters (http://haskell.cs.yale.edu/wp-content/uploads/2011/02/POPL96...)