Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writer vs WriterT in Haskell

Tags:

haskell

monads

What is the difference between Writer and WriterT in Haskell? Is one preferred over the other?

like image 382
Vlad the Impala Avatar asked Oct 03 '11 01:10

Vlad the Impala


2 Answers

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.

like image 85
hammar Avatar answered Oct 28 '22 22:10

hammar


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

like image 33
dino Avatar answered Oct 28 '22 21:10

dino