- Main.scala
authorAlexandre Bertails <bertails@gmail.com>
Sun, 08 Jan 2012 15:38:32 -0500
changeset 3 0b441c4a28ac
parent 2 24c7e2084525
child 4 411c13f1d83b
- Main.scala
aRDF/src/main/scala/Main.scala
--- a/aRDF/src/main/scala/Main.scala	Sun Jan 08 15:36:45 2012 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-// afaik, the compiler doesn't not expose the unapply method
-// for a companion object
-trait Isomorphic[A, B] {
-  def apply(x: A): B
-  def unapply(x: B): Option[A]
-}
-
-// abstract module
-trait Module {
-  type X
-  type Y <: X
-  def X: Isomorphic[Int, X]
-  def Y: Isomorphic[X, Y]
-}
-
-// an implementation relying on case classes
-object ConcreteModule extends Module {
-  sealed trait X { def v: Int = 42 }
-  object X extends Isomorphic[Int, X] {
-    def apply(_v: Int): X = new X { }
-    def unapply(x: X): Option[Int] = Some(x.v)
-  }
-  case class Y(x: X) extends X
-  // I guess the compiler could do that for me
-  object Y extends Isomorphic[X, Y]
-}
-
-object Main {
-  def foo(t: Module)(x: t.X): Unit = {
-    import t._
-    x match {
-      case Y(_y) => println("y "+_y)
-      case X(_x) => println("x "+_x)
-      case x => println("___ + " + x)
-    }
-  }
-  def bar(t: Module): Unit = {
-    import t._
-    val x: X = X(42)
-    val y: Y = Y(x)
-    foo(t)(x)
-    foo(t)(y)
-  }
-  def main(args: Array[String]) = {
-    // call bar with the concrete module
-    bar(ConcreteModule)
-  }
-}