Created
September 6, 2017 21:04
-
-
Save esarbe/9b1a767555f9853eb1c6b77cad84821c 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
object Main { | |
trait Language { self: Literal => | |
import self._ | |
def add(l: F[Int], r: F[Int]): F[Int] | |
} | |
trait Literal { | |
type F[T] | |
def num(i: Int): F[Int] | |
} | |
def expression(adder: Language) = { | |
import adder._ | |
add(num(1), num(2)) | |
} | |
val idLanguage = new Language { | |
type F[T] = T | |
def add(l: Int, r: Int): Int = l + r | |
def num(i: Int): Int = i | |
} | |
val printLanguage = new Language { | |
type F[T] = String | |
def add(l: String, r: String) = s"$l + $r" | |
def num(i: Int) = s"$i" | |
} | |
def main(args: Array[String]): Unit = { | |
println(expression(printLanguage)) | |
println(expression(idLanguage)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment