LoginSignup
1
0

More than 1 year has passed since last update.

[a] -> b より (Monoid a) => a -> b が好まれるケース

Last updated at Posted at 2023-01-10

リストに要素が追加されることはあっても、リストから要素が削除されることがないことを明示できるから。

参考文献

課題

リストから要素が削除されることを明示する場合は 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.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0