Created
September 1, 2019 15:43
-
-
Save LukaJCB/3a90f86bbedaf2bc87535acebec8ea0f to your computer and use it in GitHub Desktop.
Generalized Monoids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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