リストに要素が追加されることはあっても、リストから要素が削除されることがないことを明示できるから。
参考文献
課題
リストから要素が削除されることを明示する場合は Alternative
(MonadPlus
) を使えばよいか?それとも []
とすべきか?
追加メモ
It works just as well, but there is a big advantage to using the Writer version. It has type signature f :: Integer -> Writer (Sum Integer) Integer. We can immediately read from this that our function has a side effect that involves accumulating a number in a purely additive way. It's never going to, for example, multiply the accumulated value. The type information tells us a lot about what is going on inside the function without us having to read a single line of the implementation. The version written with State is free to do whatever it likes with the accumulated value and so it's harder to discern its purpose.