Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
object MonoidComponent {
// モノイドの定義
trait Monoid[M] {
def <>(m1: M, m2: M): M
val mempty: M
// Monoid[Int]のインスタンス定義
implicit val monoidIntInstance = new Monoid[Int] {
override def <>(m1: Int, m2: Int): Int = m1 + m2
override val mempty = 0
// <>(1, 2)のように呼び出せるようにしたいので便利関数を定義
def <>[M: Monoid](m1: M, m2: M): M = implicitly[Monoid[M]].<>(m1, m2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.