This file contains 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
22:06 ~/Projects/Kepler_5923/sandbox (ticket/5923)$ cat Macros.scala | |
import language.experimental.macros | |
import scala.reflect.macros.Context | |
trait Iso[T, U] { | |
def to(t : T) : U | |
// def from(u : U) : T | |
} | |
object Iso { | |
implicit def materializeIso[T, U]: Iso[T, U] = macro impl[T, U] | |
def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: Context): c.Expr[Iso[T, U]] = ... | |
} | |
22:06 ~/Projects/Kepler_5923/sandbox (ticket/5923)$ scala | |
Welcome to Scala version 2.10.2-20130430-211936-b00a62fd16 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_45). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> def foo[C, L](c: C)(implicit iso: Iso[C, L]) = println(iso.to(c)) | |
foo: [C, L](c: C)(implicit iso: Iso[C,L])Unit | |
scala> case class Foo(i: Int, s: String, b: Boolean) | |
defined class Foo | |
scala> foo(Foo(23, "foo", true)) | |
(23,foo,true) | |
scala> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment