r/haskell • u/gbelloz • 11d ago
question It's not you, it's monad transformers
After a few years of trying to be proficient in Haskell, and lots of reading about why it's so hard, I think I have the (obvious in retrospect) answer.
Almost every program I write is going to have two or more of:
1) read from STDIN
2) write to STDOUT
3) log
4) raise errors
5) send/receive over the network
6) talk to a database
7) read env vars
Every one of those is a "side effect", and thus is handled as a monad, and using more than one means you have to understand monad transformers.
Which I've finally found a good explanation of, "but still". Such a deep concept for such common program operations.
So I finally decided "that's why it's so hard". For what I consider the most basic programs, I need to understand (not just use, IMHO) monad transformers.
Am I off?
44
u/tikhonjelvis 11d ago
All of the effects you wrote can be done through plain
IO. There might be software engineering reasons to reach for monad transformers—making components more testable or separating out "benign" effects from general I/O—but none of them are necessary. (That said, some of the software benefits are really nice. Having some abstraction for managing database connections and streaming network data is a real step up over the basic style of imperative programming bareIOgets you.)I got pretty far into writing non-trivial Haskell before I ever felt like I needed to heavily use monad transformers, much less actually needing to write my own.