At the end of Monad Transformer Stacks section of the Monadic Adventures chapter in PureScript by Example there’s an exercise that builds on a previous one, however, I don’t get how a possible solution should work. Here’s the exercise’s text.
- (Difficult) Use the
WriterTmonad transformers to reimplement the document printing library which we wrote earlier using the
Readermonad. Instead of using
lineto emit strings and
catto concatenate strings, use the
Array Stringmonoid with the
WriterTmonad transformer, and
tellto append a line to the result.
For me this tells that I should rework the previous document printing solution (I have one similar to this) in a way that I don’t use the
cat functions and somehow I should use the
tell function instead of these, but I’m not sure how is this possible.
An example of how using this new solution might go would be useful, along the lines of this example from a previous section.
render $ cat [ line "Here is some indented text:" , indent $ cat [ line "I am indented" , line "So am I" , indent $ line "I am even more indented" ] ]
Any insight is gladly appreciated.
Mentioning @paf31 in hope of first-hand insight.