Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to create transform two equivalent types in Scala reflection into two equal types?
    primarykey
    data
    text
    <p>Consider the following:</p> <pre><code>scala&gt; import scala.reflect.runtime.universe._ import scala.reflect.runtime.universe._ scala&gt; typeOf[Boolean] res23: reflect.runtime.universe.Type = Boolean scala&gt; typeOf[scala.Boolean] res24: reflect.runtime.universe.Type = Boolean scala&gt; res23 == res24 res25: Boolean = true scala&gt; typeOf[java.lang.Boolean] res26: reflect.runtime.universe.Type = Boolean scala&gt; res23 == res26 res27: Boolean = false scala&gt; class Foo { def bf(arg: Boolean) = ??? } defined class Foo scala&gt; typeOf[Foo] res28: reflect.runtime.universe.Type = Foo scala&gt; res28.member(newTermName("bf")).asMethod res30: reflect.runtime.universe.MethodSymbol = method bf scala&gt; res30.paramss.head.head res31: reflect.runtime.universe.Symbol = value arg scala&gt; res31.typeSignature res32: reflect.runtime.universe.Type = scala.Boolean scala&gt; res32 == res23 res33: Boolean = false scala&gt; res32 =:= res23 res37: Boolean = true </code></pre> <p>So the type obtained via the typeOf[Boolean] function is equivalent to the type obtained via inspecting a method, but it is not equal.</p> <p>Is there a way to transform two equivalent types into some canonical representation where the results will be equal? I'd like to be able to use them for things like keys in maps.</p> <h2>Edit:</h2> <p>To be more clear, what I'm looking for is something along the lines of (not a real repl session):</p> <pre><code>scala&gt;val tp1 = // some type scala&gt;val tp2 = // equivalent type obtained another way scala&gt;tp1 == tp2 res1: Boolean = false scala&gt;tp1 =:= tp2 res2: Boolean = true scala&gt;val ctp1 = tp1.canonical scala&gt;val ctp2 = tp2.canonical scala&gt;ctp1 == ctp2 res3: Boolean = true scala&gt;ctp1 =:= tp1 res4: Boolean = true scala&gt;ctp2 =:= tp2 res5: Boolean = true </code></pre> <p>So equivalence is preserved by the transformation. I also need it to work on parameterized types.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload