fmidue / output-blocks

0 stars 0 forks source link

let text lines "accumulate" #1

Closed jvoigtlaender closed 1 year ago

jvoigtlaender commented 1 year ago

It would be nice if code like this:

do
                      translate $ do
                        german "Gegeben seien ... \n"
                      translate $ do
                        german (unwords some-expression)
                      translate $ do
                        german "\nAußerdem ... \n"
                      translate $ do
                        german (unwords ...)
                      translate $ do
                        german "\nUnd ... \n"
                      translate $ do
                        ...

could be written like this:

                      translate $ do
                        german "Gegeben seien ... \n"
                        german (unwords some-expression)
                        german "\nAußerdem ... \n"
                        german (unwords ...)
                        german "\nUnd ... \n"
                        ...

(The reason for having individual german lines, instead of somehow assembling them inside a [iii|...] or so, is to enable spell-checking exceptions with a pattern like https://github.com/fmidue/logic-tasks/blob/efbd462786a589ac9085481f88c8b457ab88e172/.github/actions/spelling/patterns.txt#L14-L15.)

Is it as easy as replacing M.insert in https://github.com/fmidue/output-monad/blob/5ceb8acda690474be0dbd91e1c5bcae3535656fc/output-monad/src/Control/Monad/Output.hs#L214-L215 by M.insertWith (++)?

marcellussiegburg commented 1 year ago

Yes, this should (basically) be the solution! (it should probably be insertWith (flip (++)) in order to append rather than prepend ...) And for consistency this should also be applied to https://github.com/fmidue/output-monad/blob/5ceb8acda690474be0dbd91e1c5bcae3535656fc/output-monad/src/Control/Monad/Output.hs#L211-L212