What is the difference between Writer
and WriterT
in Haskell? Is one preferred over the other?
The difference is that Writer
is a monad, whereas WriterT
is a monad transformer, i.e. you give it some underlying monad, and it gives you back a new monad with "writer" features on top. If you only need the writer-specific features, use Writer
. If you need to combine its effects with some other monad, such as IO
, use WriterT
.
To add to the excellent explanations above, I'd like to also point to this paper. Has helped me quite a bit:
Monad Transformers Step By Step
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With