Created
September 1, 2014 15:59
-
-
Save samskivert/126b4195461e7c0613ad to your computer and use it in GitHub Desktop.
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
object R2 { | |
trait R2[A] { | |
def f (a :A) :A | |
} | |
trait R2Gen { | |
def gen[A] :R2[A] | |
} | |
def foo (gen :R2Gen) { | |
val x = "one" | |
val r2str = gen.gen[String] | |
println("str " + r2str.f(x)) | |
val y = 1 | |
val r2int = gen.gen[Int] | |
println("int " + r2int.f(y)) | |
} | |
def main (args :Array[String]) { | |
foo(new R2Gen { | |
def gen[A] = new R2[A] { | |
def f (a :A) = a | |
} | |
}) | |
} | |
} |
Just to relieve my own shame:
object R2 {
trait R2Gen {
def gen[A] :A => A
}
def foo (gen :R2Gen) {
val x = "one"
val r2str = gen.gen[String]
println("str " + r2str(x))
val y = 1
val r2int = gen.gen[Int]
println("int " + r2int(y))
}
def main (args :Array[String]) {
foo(new R2Gen {
def gen[A] = (a :A) => a
})
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now that I think about it, R2 is unnecessary. I can just use Function1.