Last active
January 13, 2018 22:21
-
-
Save ruslanbogun/d7548a329d5192c4077ab375474f6b35 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
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