Skip to content

Instantly share code, notes, and snippets.

@LukaJCB
Created September 1, 2019 15:43
Show Gist options
  • Save LukaJCB/3a90f86bbedaf2bc87535acebec8ea0f to your computer and use it in GitHub Desktop.
Save LukaJCB/3a90f86bbedaf2bc87535acebec8ea0f to your computer and use it in GitHub Desktop.
Generalized Monoids
trait Op[A] {
def apply(x: A, y: A): A
}
class Multiply extends Op[Int] {
def apply(x: Int, y: Int) = x * y
}
trait Semigroup[A, O <: Op[A]]
val intSemigroup = new Semigroup[Int, Multiply]{}
trait Monoid[A, O <: Op[A], I <: A with Singleton] extends Semigroup[A, O]
val intMonoid = new Monoid[Int, Multiply, 0]{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment