|
> Monad transformers exist independent of the fact that monads don't compose. Can you explain what you mean by 'monad transformers exist because monads don't compose'? 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: A ground-breaking attempt to better solve the overall
problem began with Moggi’s proposal to use monads to
structure denotational semantics. Wadler popularized
Moggi’s ideas in the functional programming community
by showing that many type constructors (such as List) were
monads and how monads could be used in a variety of
settings, many with an “imperative” feel (such as in Peyton
Jones & Wadler). Wadler’s interpreter design, however,
treats the interpreter monad as a monolithic structure which
has to be reconstructed every time a new feature is added.
More recently, Steele proposed pseudomonads as a way
to compose monads and thus build up an interpreter from
smaller parts, but he failed to properly incorporate important
features such as an environment and store, and struggled
with restrictions in the Haskell type system when trying
to implement his ideas. In fact, pseudomonads are really
just a special kind of monad transformer, first suggested by
Moggi as a potential way to leave a “hole” in a monad
for further extension.
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...) |
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.