Created
April 20, 2012 20:59
-
-
Save retronym/2431859 to your computer and use it in GitHub Desktop.
unimplicitly
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
scala> import scala.language.experimental.macros | |
import scala.language.experimental.macros | |
scala> def unimplicitlyImpl[A: c.TypeTag](c: reflect.makro.Context) = { | |
| val A = implicitly[c.TypeTag[A]].tpe | |
| val i = c.inferImplicitValue(A, silent = true) | |
| if (i == c.mirror.EmptyTree) c.reify(()) | |
| else sys.error("unexpected implicit of type %s: %s".format(A, i)) | |
| } | |
unimplicitlyImpl: [A](c: scala.reflect.makro.Context)(implicit evidence$1: c.TypeTag[A])c.mirror.Expr[Unit] | |
scala> def unimplicitly[A] = macro unimplicitlyImpl[A] | |
unimplicitly: [A]=> Unit | |
scala> unimplicitly[String] | |
scala> unimplicitly[Int => Int] | |
<console>:11: error: exception during macro expansion: | |
java.lang.RuntimeException: unexpected implicit of type Int => Int: scala.this.Predef.conforms[Int] | |
at scala.sys.package$.error(package.scala:27) | |
at .m(<console>:11) | |
unimplicitly[Int => Int] | |
^ |
Ah thanks... my REPL cut-n-pastery wasn't up to scratch, thanks to the crashy tab completion for SIP-18.
scala> import language.expReplGlobal.abort: no-symbol does not have an owner (this is a bug: scala version 2.10.0-20120420-170445-56c1f29250)
error: no-symbol does not have an owner (this is a bug: scala version 2.10.0-20120420-170445-56c1f29250)
sac
<console>:7: error: value expsac is not a member of object language
import language.expsac
Heh, with a dash of intentional ambiguity macros aren't needed at all: http://paste.pocoo.org/show/584923/
You do know you can edit (and version) your gists, don't you?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better go for