Adding :kind command to scala repl

166 views
Skip to first unread message

George Leontiev

unread,
Mar 27, 2013, 2:57:42 PM3/27/13
to scala-i...@googlegroups.com
Hello again,

I'm trying to implement a :kind command for scala repl based on this thing by Eugene Yokota, and I'm facing some problems with it. It works with reflect.runtime.universe.Types, but repl gives you Strings with user input. So, there are two ways I tried to approach converting Strings to Types:
first -- with the help of scala.reflect.ToolBox (as explained here)
second -- with the help of IMain instance (as implemented for the :type command)

The first one works just fine for the types, available at repl's compile time. Meaning, if I start it like this:
ANT_OPTS="-Xmx2G -Xss2M -server -XX:MaxPermSize=180M" ant quick.clean && ant build && ./build/pack/bin/scala -cp /home/folone/.ivy2/local/org.scalaz/scalaz-core_2.10/7.0-SNAPSHOT/bundles/scalaz-core_2.10.jar
then both :k Option and :k Either work as expected, but :k scalaz.Monad does not, complaining that it cannot find scalaz.Monad.
The second approach sees scalaz.Monad and all the types in scope, but matches all of them here.

Is there a way to do what I'm trying to accomplish? What am I doing wrong?

Thanks.

Eugene Burmako

unread,
Mar 27, 2013, 3:38:24 PM3/27/13
to <scala-internals@googlegroups.com>
Have you tried using `currentMirror.staticClass("scalaz.Monad")`? Once you have a symbol at hand, you could get to its signature.


--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

George Leontiev

unread,
Mar 27, 2013, 4:47:40 PM3/27/13
to scala-i...@googlegroups.com
Thanks for your answer, I just did. Works for scala.Option, but still fails for scalaz.Monad:

scala> :k scala.Option
Option's kind is * -> *. This is a type constructor: a 1st-order-kinded type.

scala> :k scalaz.Monad
scala.reflect.internal.MissingRequirementError: class scalaz.Monad in JavaMirror with primordial classloader with boot classpath [/usr/lib/jvm/java-7-openjdk/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-7-openjdk/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk/jre/lib/netx.jar:/usr/lib/jvm/java-7-openjdk/jre/lib/plugin.jar:/usr/lib/jvm/java-7-openjdk/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk/jre/lib/jfr.jar:/usr/lib/jvm/java-7-openjdk/jre/classes:/home/folone/workspace/scala/build/pack/lib/jline.jar:/home/folone/workspace/scala/build/pack/lib/scala-actors.jar:/home/folone/workspace/scala/build/pack/lib/scala-compiler.jar:/home/folone/workspace/scala/build/pack/lib/scala-library.jar:/home/folone/workspace/scala/build/pack/lib/scala-partest-javaagent.jar:/home/folone/workspace/scala/build/pack/lib/scala-partest.jar:/home/folone/workspace/scala/build/pack/lib/scala-reflect.jar:/home/folone/workspace/scala/build/pack/lib/scalacheck.jar:/home/folone/workspace/scala/build/pack/lib/scalap.jar] not found.
at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:16)
at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:17)
at scala.reflect.internal.Mirrors$RootsBase$$anonfun$getModuleOrClass$3.apply(Mirrors.scala:51)
at scala.reflect.internal.Mirrors$RootsBase$$anonfun$getModuleOrClass$3.apply(Mirrors.scala:51)
at scala.reflect.internal.Symbols$Symbol.orElse(Symbols.scala:2300)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:50)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:63)
at scala.reflect.internal.Mirrors$RootsBase.staticModuleOrClass(Mirrors.scala:74)
at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:123)
at scala.reflect.internal.Mirrors$RootsBase.staticClass(Mirrors.scala:21)
at scala.tools.nsc.interpreter.package$IMainOps.kindCommandInternal(package.scala:161)
at scala.tools.nsc.interpreter.ILoop.scala$tools$nsc$interpreter$ILoop$$kindCommand(ILoop.scala:296)
at scala.tools.nsc.interpreter.ILoop$$anonfun$standardCommands$15.apply(ILoop.scala:224)
at scala.tools.nsc.interpreter.ILoop$$anonfun$standardCommands$15.apply(ILoop.scala:224)
at scala.tools.nsc.interpreter.LoopCommands$LineCmd.apply(LoopCommands.scala:60)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:521)
at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:382)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:399)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:682)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:668)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:668)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:95)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:668)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:80)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:93)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:102)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

That entry seems to have slain the compiler.  Shall I replay
your session? I can re-run each line except the last one.
[y/n]
Abandoning crashed session.

Looks like scalaz.jar is not on that boot classpath.

Eugene Burmako

unread,
Mar 27, 2013, 5:07:35 PM3/27/13
to <scala-internals@googlegroups.com>
You need to create the mirror from a repl classloader. Iirc it's usually registered as a context classloader: https://github.com/scalamacros/kepler/blob/2f3a7fa417f7ba92251fdae53e5548f081c2fd04/src/compiler/scala/tools/nsc/interpreter/IMain.scala#L324.

George Leontiev

unread,
Mar 28, 2013, 5:53:17 AM3/28/13
to scala-i...@googlegroups.com, fol...@lambda-calcul.us
In case there is someone interested in the :kind feature progress, thanks to Eugene there is a working prototype now (https://gist.github.com/folone/5261743). It has some flaws though. I decided to document where the development is now and assemble a minimum reproducible example. Here's a SO question describing all those things: http://stackoverflow.com/questions/15678616/getting-type-information-inside-scala-repl-via-imain
Reply all
Reply to author
Forward
0 new messages