Home Monoid
Post
Cancel

Monoid

  • Every monoid is a semiGroup but not the other way around. It has all characteristics of a semigroup + more
  • Laws:
    • Left Identity append(a, 0) == a
    • Right Identity append(0, a) == a
  • NotEmpty is not a monoid since it has no zero value.
  • Permission systems should be implemented as monoidal systems.
1
2
3
4
trait Monoid[A] extends SemiGroup[A] {
  def zero: A // example: Zero value for a string is ""
  // Note that we have inherited append from SemiGroup
}

Resources

  1. Functional Scala by John A. De Goes (Toronto Edition)
  2. Scalaz Monoid
This post is licensed under CC BY 4.0 by the author.
Contents

Functor

SemiGroup

Comments powered by Disqus.