Created
March 28, 2021 16:16
-
-
Save deanwampler/58066a74670639ccecd67bbe7ec78efd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import scala.annotation.targetName | |
trait Semigroup[T]: | |
extension (t: T) | |
infix def combine(other: T): T | |
@targetName("plus") def <+>(other: T): T = t.combine(other) | |
trait Monoid[T] extends Semigroup[T]: | |
def unit: T | |
given NumericMonoid[T](using num: Numeric[T]): Monoid[T] with | |
def unit: T = num.zero | |
extension (t: T) infix def combine(other: T): T = num.plus(t, other) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment