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
import shapeless._ | |
object Test extends App { | |
implicitly[Generic.Aux[(Int, Char), Int :: Char :: HNil]] | |
} | |
[error] ~/Projects/shapeless-test/Test.scala:3: could not find implicit value for parameter e: shapeless.Generic.Aux[(Int, Char),shapeless.::[Int,shapeless.::[Char,shapeless.HNil]]] | |
[error] implicitly[Generic.Aux[(Int, Char), Int :: Char :: HNil]] | |
[error] ^ |
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
23:03 ~/Projects/sbt-example-paradise (master)$ sbt | |
[info] Loading project definition from /Users/xeno_by/Projects/sbt-example-paradise/project | |
[info] Updating {file:/Users/xeno_by/Projects/sbt-example-paradise/project/}sbt-example-paradise-build... | |
[info] Resolving org.fusesource.jansi#jansi;1.4 ... | |
[info] downloading http://repo1.maven.org/maven2/net/virtual-void/sbt-dependency-graph_2.10_0.13/0.7.4/sbt-dependency-graph-0.7.4.jar ... | |
[info] [SUCCESSFUL ] net.virtual-void#sbt-dependency-graph;0.7.4!sbt-dependency-graph.jar (986ms) | |
[info] downloading http://repo1.maven.org/maven2/com/github/mdr/ascii-graphs_2.10/0.0.3/ascii-graphs_2.10-0.0.3.jar ... | |
[info] [SUCCESSFUL ] com.github.mdr#ascii-graphs_2.10;0.0.3!ascii-graphs_2.10.jar (780ms) | |
[info] downloading http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.1/scala-library-2.10.1.jar ... | |
[info] [SUCCESSFUL ] org.scala-lang#scala-library;2.10.1!scala-library.jar (2760ms) |
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
import scala.reflect.macros.Context | |
import scala.language.experimental.macros | |
import scala.reflect.api.Liftable | |
object liftableMacro { | |
implicit def liftableCaseClass[T]: Liftable[T] = macro impl | |
def impl(c: Context): c.Tree = { | |
import c.universe._ | |
val spliced: List[Tree] = List(q"???") | |
val s = "" |
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
[error] /Users/xeno_by/Projects/macros-playground/macros/src/main/scala/Macros.scala:50: Can't splice String(""), consider | |
[error] Apply(Select(New(Ident(TermName(${""}))), | |
[error] ^ |
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
// As I mentioned before, macros can do everything that the compiler can do by judicious application of casts. | |
// Here we get a reference to a typechecker servicing the expansion and from it - to the list of lexical scopes. | |
// Having that information at hand, we can report the list of variables in both lexical and "this" scopes. | |
// Since casts are involved here, there's no guarantee that this will work even in-between minor releases of Scala. | |
// Therefore I would advise going this route only if there are no workarounds for your particular use case. | |
// Please feel free to email me to ask for workarounds (but please don't leave comments here, because I don't get notified about them) | |
import scala.reflect.macros.Context | |
import scala.language.experimental.macros |
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
private[this] val r1: reflect.runtime.universe.Tree = { | |
import scala.reflect.api.Liftable; | |
{ | |
final class $anon extends AnyRef with scala.reflect.api.Liftable[A] { | |
def <init>(): <$anon: scala.reflect.api.Liftable[A]> = { | |
$anon.super.<init>(); | |
() | |
}; | |
def apply(universe: scala.reflect.api.Universe, cc: A): universe.Tree = { | |
val ttree: universe.TypeTree = universe.TypeTree(universe.typeOf[A]({ |
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
case class A() | |
object Test extends App { | |
import Macros._ | |
import scala.reflect.runtime.universe._ | |
val c1 = A() | |
val r1 = q"$c1" | |
} |
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
import scala.reflect.macros.WhiteboxContext | |
import scala.language.experimental.macros | |
import scala.reflect.api.Liftable | |
import scala.reflect.macros.Universe | |
import scala.reflect.api.Position | |
object Macros { | |
implicit def liftableCaseClass[T]: Liftable[T] = macro impl[T] | |
def impl[T: c.WeakTypeTag](c: WhiteboxContext) = { | |
import c.universe._ |
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
15:31 ~$ parse 'enum Day(foo: Int) = x' | |
[[syntax trees at end of parser]]// Scala source: tmpVbz6xn | |
package <empty> { | |
class wrapper extends scala.AnyRef { | |
def <init>() = { | |
super.<init>(); | |
() | |
}; | |
enum.Day.update((foo: Int), x) | |
} |
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
09:32 ~$ prj | |
09:32 ~/Projects$ cd enum-paradise/ | |
09:32 ~/Projects/enum-paradise (java-enums-via-macro-annotations)$ sbt | |
[info] Loading project definition from /Users/xeno_by/Projects/enum-paradise/project | |
[info] Set current project to root (in build file:/Users/xeno_by/Projects/enum-paradise/) | |
> clean | |
[success] Total time: 0 s, completed Nov 12, 2013 9:32:25 AM | |
> compile | |
[info] Updating {file:/Users/xeno_by/Projects/enum-paradise/}macros... | |
[info] Updating {file:/Users/xeno_by/Projects/enum-paradise/}root... |