Skip to content

Instantly share code, notes, and snippets.

@deanwampler
Last active December 27, 2020 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deanwampler/6c1496da43bf338019beee2c5ea70ce4 to your computer and use it in GitHub Desktop.
Save deanwampler/6c1496da43bf338019beee2c5ea70ce4 to your computer and use it in GitHub Desktop.
Example of Scala 3 syntax for type classes
// 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