fork(2) download
  1. object Main {
  2.  
  3. trait Concat[A] { def ++ (x: A, y: A): A }
  4. implicit object IntConcat extends Concat[Int] {
  5. override def ++ (x: Int, y: Int): Int = (x.toString + y.toString).toInt
  6. }
  7.  
  8. implicit class ConcatOperators[A: Concat](x: A) {
  9. def ++ (y: A) = implicitly[Concat[A]].++(x, y)
  10. }
  11.  
  12. def main(args: Array[String]): Unit = {
  13. val a = 1234
  14. val b = 765
  15.  
  16. val c = a ++ b
  17.  
  18. println(c)
  19.  
  20. val d = highOrderTest(a, b)(IntConcat.++)
  21.  
  22. println(d)
  23. }
  24.  
  25. def highOrderTest[A](x: A, y: A)(fun: (A, A) => A) = fun(x, y)
  26.  
  27. }
Success #stdin #stdout 0.39s 382144KB
stdin
Standard input is empty
stdout
1234765
1234765