Skip to content

Instantly share code, notes, and snippets.

@ruslanbogun
Last active January 13, 2018 22:21
Show Gist options
  • Save ruslanbogun/d7548a329d5192c4077ab375474f6b35 to your computer and use it in GitHub Desktop.
Save ruslanbogun/d7548a329d5192c4077ab375474f6b35 to your computer and use it in GitHub Desktop.
type Plus
type Minus
trait Expression[E] {
def value(a: Int, b: Int): Int
}
def expression[E](a: Int, b: Int)(implicit t: Expression[E]) = t.value(a, b)
implicit object plus extends Expression[Plus] {
def value(a: Int, b: Int) = a + b
}
implicit object minus extends Expression[Minus] {
def value(a: Int, b: Int) = a - b
}
expression[Plus](3, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment