Using a nun writer

I see how Writer monad allows you to create a list of strings along with a set of calculations, but what is it? It seems very rude. It seems that there are several examples of using the "real world" of a writer. What kind of monad is it, really useful, in addition to didactic goals?

The lack of examples is apparently one of the barriers to learning Haskell. It would be nice if there was a useful Haskell cookbook. (So, are there any?)

+4
source share
3 answers

WriterIMO itself is quite useless. Yes, "entering into pure computation" makes sense, but for a simple clean computation you will have to rewrite everything in order to use monadic bindings. The result will not be much better than if you had just rewritten it to manually concatenate the log information.

Which is really useful, however, is to add a slot WriterTto the monad stack that you have, so that you get the option of logging with virtually no change in definitions. This is what is done in the "big powerful" monads, like the ones used in Yesod, etc., But WriterTyou can also apply to any simple special monad that you use.

+4
source
+5

, , . "" - , , , .

, :

  • ( )
  • ( )
  • ( )
  • , , , .
+1

Source: https://habr.com/ru/post/1569004/


All Articles