Created
August 26, 2011 14:39
-
-
Save kmizu/1173542 to your computer and use it in GitHub Desktop.
Emulating separate compilation in Scala
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
//Link testa and testz. | |
//To compile this file, testz.scala, testa.scala, and test.scala must be compiled. | |
//In this approach, we can select different implementation of test.A | |
object link extends test with testa with testz { | |
class A extends super[testa].A with super[testz].A | |
def main(args: Array[String]) { | |
val a = new A | |
println(a.aaa()) | |
println(a.aaa2()) | |
println(a.zzz()) | |
println(a.zzz2()) | |
} | |
} |
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
//Header file | |
trait test { | |
trait A { | |
def aaa(): Int | |
def aaa2(): Int | |
def zzz(): Int | |
def zzz2(): Int | |
} | |
} |
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
//Partial implementation of header.A | |
//This file can be compiled only if test.scala is compiled | |
trait testa {header: test => | |
trait A extends header.A { | |
def aaa() = zzz2 | |
def aaa2() = 100 | |
} | |
} |
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
//Partial implementation of header.A | |
//This file can be compiled only if test.scala is compiled | |
trait testz {header: test => | |
trait A extends header.A { | |
def zzz() = aaa2() | |
def zzz2() = 22 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment