Skip to content

Instantly share code, notes, and snippets.

@samskivert
Created September 1, 2014 15:59
Show Gist options
  • Save samskivert/126b4195461e7c0613ad to your computer and use it in GitHub Desktop.
Save samskivert/126b4195461e7c0613ad to your computer and use it in GitHub Desktop.
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
}
})
}
}
@samskivert
Copy link
Author

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