Created
February 12, 2011 22:09
-
-
Save retronym/824183 to your computer and use it in GitHub Desktop.
scalac -Xprint:typer
This file contains hidden or 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
trait Creator[A] { | |
def create: A | |
} | |
object Creator { | |
def create[A](f: => A): Creator[A] = new Creator[A] { def create: A = f } | |
implicit def IntCreator = create(0) | |
implicit def StringCreator = create("") | |
implicit def ArrayCreator[A: ClassManifest] = create(Array[A]()) | |
implicit def ListCreator[A] = create(List[A]()) | |
implicit def Function0Creator[A: Creator] = create(() => implicitly[Creator[A]].create) | |
} | |
object GMA { | |
def giveMeA[A: Creator]: A = implicitly[Creator[A]].create | |
giveMeA[Int] | |
giveMeA[Function0[String]] | |
} |
This file contains hidden or 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
~/code/scratch/tc: scalac -Xprint:typer tc.scala | |
[[syntax trees at end of typer]]// Scala source: tc.scala | |
package <empty> { | |
abstract trait Creator[A >: Nothing <: Any] extends scala.AnyRef { | |
def create: A | |
}; | |
final object Creator extends java.lang.Object with ScalaObject { | |
def this(): object Creator = { | |
Creator.super.this(); | |
() | |
}; | |
def create[A >: Nothing <: Any](f: => A): Creator[A] = { | |
final class $anon extends java.lang.Object with Creator[A] { | |
def this(): anonymous class $anon = { | |
$anon.super.this(); | |
() | |
}; | |
def create: A = f | |
}; | |
new $anon() | |
}; | |
implicit def IntCreator: Creator[Int] = Creator.this.create[Int](0); | |
implicit def StringCreator: Creator[java.lang.String] = Creator.this.create[java.lang.String](""); | |
implicit def ArrayCreator[A >: Nothing <: Any](implicit evidence$1: ClassManifest[A]): Creator[Array[A]] = Creator.this.create[Array[A]](scala.Array.apply[A]()(evidence$1)); | |
implicit def ListCreator[A >: Nothing <: Any]: Creator[List[A]] = Creator.this.create[List[A]](immutable.this.Nil); | |
implicit def Function0Creator[A >: Nothing <: Any](implicit evidence$2: Creator[A]): Creator[() => A] = Creator.this.create[() => A]((() => scala.this.Predef.implicitly[Creator[A]](evidence$2).create)) | |
}; | |
final object GMA extends java.lang.Object with ScalaObject { | |
def this(): object GMA = { | |
GMA.super.this(); | |
() | |
}; | |
def giveMeA[A >: Nothing <: Any](implicit evidence$3: Creator[A]): A = scala.this.Predef.implicitly[Creator[A]](evidence$3).create; | |
GMA.this.giveMeA[Int](Creator.IntCreator); | |
GMA.this.giveMeA[() => String](Creator.Function0Creator[String](Creator.StringCreator)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment