Last active
December 27, 2020 15:28
-
-
Save deanwampler/6c1496da43bf338019beee2c5ea70ce4 to your computer and use it in GitHub Desktop.
Example of Scala 3 syntax for type classes
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
// Adapted from this Dotty documentation: | |
// https://dotty.epfl.ch/docs/reference/contextual/type-classes.html | |
trait Semigroup[T]: | |
extension (t: T) | |
def combine(other: T): T | |
def <+>(other: T): T = t.combine(other) | |
trait Monoid[T] extends Semigroup[T]: | |
def unit: T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment