secret
Created

working on :kind

  • Download Gist
1.option
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
BUILD SUCCESSFUL
Total time: 14 seconds
Welcome to Scala version 2.11.0-20130328-114111-c5a0f8e9bd (OpenJDK 64-Bit Server VM, Java 1.7.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
 
scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'. **
** scala.tools.nsc._ has been imported **
** global._, definitions._ also imported **
** Try :help, :vals, power.<tab> **
 
scala> def kindCommandInternal(expr: String, verbose: Boolean): String = {
| //import scala.reflect.runtime.universe._
| def kind(a: Type): String = {
| def typeKind(sig: Type): String = sig match {
| case PolyType(params, resultType) =>
| (params map { p =>
| typeKind(p.typeSignature) match {
| case "*" => "*"
| case s => "(" + s + ")"
| }
| }).mkString(" -> ") + " -> *"
| case _ => "*"
| }
| def typeSig(tpe: Type): Type = tpe match {
| case SingleType(pre, sym) => sym.companionSymbol.typeSignature
| case ExistentialType(q, TypeRef(pre, sym, args)) => sym.typeSignature
| case TypeRef(pre, sym, args) => sym.typeSignature
| case ClassInfoType(ext, scope, sym) => sym.typeSignature
| }
| val sig = typeSig(a)
| val s = typeKind(sig)
| val result = sig.typeSymbol.name + "'s kind is " + s
| val additionalInfo = if(verbose)
| s match {
| case "*" =>
| "\nThis is a proper type."
| case x if !(x contains "(") =>
| "\nThis is a type constructor: a 1st-order-kinded type."
| case x =>
| "\nThis is a type constructor that takes type constructor(s): a higher-kinded type."
| }
| else ""
| result + additionalInfo
| }
| //val m = ru.runtimeMirror(intp.classLoader)
| //val typ = m.staticClass(expr.trim).toType
| val context = global.analyzer.rootContext(NoCompilationUnit)
| val typ = context.lookupSymbol(expr.trim: TypeName, _ => true).symbol.toType
| kind(typ)
| }
kindCommandInternal: (expr: String, verbose: Boolean)String
 
scala> kindCommandInternal("Option", false)
res0: String = Option's kind is * -> *
 
scala> kindCommandInternal("scala.Option", false)
scala.MatchError: <notype> (of class scala.reflect.internal.Types$NoType$)
at .typeSig$1(<console>:85)
at .kind$1(<console>:91)
at .kindCommandInternal(<console>:110)
at .<init>(<console>:38)
at .<clinit>(<console>)
at $anonfun$1.apply(<console>:7)
at $anonfun$1.apply(<console>:6)
at scala.reflect.internal.SymbolTable.enteringPhase(SymbolTable.scala:214)
at scala.tools.nsc.interpreter.Phased$class.atCurrent(Phased.scala:68)
at scala.tools.nsc.interpreter.Power$$anon$3.atCurrent(Power.scala:316)
at .<init>(<console>:6)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:751)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:966)
at scala.tools.nsc.interpreter.IMain$WrappedRequest$$anonfun$loadAndRunReq$1.apply(IMain.scala:613)
at scala.tools.nsc.interpreter.IMain$WrappedRequest$$anonfun$loadAndRunReq$1.apply(IMain.scala:612)
at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
at scala.tools.nsc.util.AbstractFileClassLoader.asContext(AbstractFileClassLoader.scala:19)
at scala.tools.nsc.interpreter.IMain$WrappedRequest.loadAndRunReq(IMain.scala:612)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:539)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:535)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:574)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:619)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:531)
at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:387)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:404)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:687)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:673)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:673)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:95)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:673)
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)
2.monad
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
scala> kindCommandInternal("scalaz.Monad", false)
scala.MatchError: <notype> (of class scala.reflect.internal.Types$NoType$)
at .typeSig$1(<console>:85)
at .kind$1(<console>:91)
at .kindCommandInternal(<console>:110)
at .<init>(<console>:35)
at .<clinit>(<console>)
at $anonfun$1.apply(<console>:7)
at $anonfun$1.apply(<console>:6)
at scala.reflect.internal.SymbolTable.enteringPhase(SymbolTable.scala:214)
at scala.tools.nsc.interpreter.Phased$class.atCurrent(Phased.scala:68)
at scala.tools.nsc.interpreter.Power$$anon$3.atCurrent(Power.scala:316)
at .<init>(<console>:6)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:751)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:966)
at scala.tools.nsc.interpreter.IMain$WrappedRequest$$anonfun$loadAndRunReq$1.apply(IMain.scala:613)
at scala.tools.nsc.interpreter.IMain$WrappedRequest$$anonfun$loadAndRunReq$1.apply(IMain.scala:612)
at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
at scala.tools.nsc.util.AbstractFileClassLoader.asContext(AbstractFileClassLoader.scala:19)
at scala.tools.nsc.interpreter.IMain$WrappedRequest.loadAndRunReq(IMain.scala:612)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:539)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:535)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:574)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:619)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:531)
at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:387)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:404)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:687)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:673)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:673)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:95)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:673)
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)
 
 
scala> import scalaz._
import scalaz._
 
scala> kindCommandInternal("Monad", false)
scala.MatchError: <notype> (of class scala.reflect.internal.Types$NoType$)
at .typeSig$1(<console>:85)
at .kind$1(<console>:91)
at .kindCommandInternal(<console>:110)
at .<init>(<console>:38)
at .<clinit>(<console>)
at $anonfun$1.apply(<console>:7)
at $anonfun$1.apply(<console>:6)
at scala.reflect.internal.SymbolTable.enteringPhase(SymbolTable.scala:214)
at scala.tools.nsc.interpreter.Phased$class.atCurrent(Phased.scala:68)
at scala.tools.nsc.interpreter.Power$$anon$3.atCurrent(Power.scala:316)
at .<init>(<console>:6)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:751)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:966)
at scala.tools.nsc.interpreter.IMain$WrappedRequest$$anonfun$loadAndRunReq$1.apply(IMain.scala:613)
at scala.tools.nsc.interpreter.IMain$WrappedRequest$$anonfun$loadAndRunReq$1.apply(IMain.scala:612)
at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
at scala.tools.nsc.util.AbstractFileClassLoader.asContext(AbstractFileClassLoader.scala:19)
at scala.tools.nsc.interpreter.IMain$WrappedRequest.loadAndRunReq(IMain.scala:612)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:539)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:535)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:574)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:619)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:531)
at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:387)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:404)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:687)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:673)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:673)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:95)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:673)
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.