Reputation: 15882
What is the difference between Writer
and WriterT
in Haskell? Is one preferred over the other?
Upvotes: 10
Views: 1656
Reputation: 1133
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
Upvotes: 4
Reputation: 139930
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
.
Upvotes: 16