5 ms·
>Even though it provides denotational semantics in the categorical setting for various side-effecting constructs the thing is inherently non-compositional. You
by d4rkph1b3r 11y ago
>Even though it provides denotational semantics in the categorical setting for various side-effecting constructs the thing is inherently non-compositional.
You don't know what this means. Monads are precisely about composition.
- rntz 11y agoMonads themselves don't compose nicely. There's no guarantee that the composition of two monads is itself a monad, for example. That's why Haskell has monad transformers. But monad transformers are quite hard to reason about (they're not even commutative). It's true that in a certain sense monads are "about composition", but that doesn't mean they aren't without issues, and I certainly think it's appropriate to call monads non-declarative. In fact, I think "being in a monad" is more or less the essence of what it is to be imperative - which is why they're useful! Quite often we want to be imperative. The word "compositional" is quite vague. I wish people would stop tossing it around so lightly without explaining what they meant by it.
- smadge 11y agoTo add on: For example, monads don't "compose" as nicely as applicatives. You can automatically compose two applicatives and have a guarantee the the result obeys the applicative laws. Like you say, for monads you would have to write your own monad transformer, and hopefully verify it is still a law abiding monad. You don't have to write a transformer for applicatives.
- willtim 11y agoMonad transformers are not the only way of combining effects.
- dkarapetyan 11y agoYes, they deal with Kleisli composition (which I intuitively think of as taking regular composition and "twisting" it with a monad) but that is different from what I meant. You can't take two different Kleisli arrows twisted with two different monads and combine them in an obvious way the same way you can compose/combine regular arrows. That is why all the tricks with transformers exist. You somehow have to get everything to be a monad again because Kleisli arrows can't cross monad boundaries.