Created
September 23, 2011 11:43
-
-
Save oxbowlakes/1237174 to your computer and use it in GitHub Desktop.
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
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) Server VM, Java 1.6.0_18). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> type Tagged[U] = { type Tag = U } | |
defined type alias Tagged | |
scala> type @@[T, U] = T with Tagged[U] | |
defined type alias $at$at | |
scala> object O { | |
| def tag[T] = new { def apply[@specialized(scala.Int, scala.Long) U](u: U): U with Tagged[T] = u.asInstanceOf[U @@ T] } | |
| } | |
defined module O | |
scala> :javap O | |
Compiled from "<console>" | |
public final class O$ extends java.lang.Object implements scala.ScalaObject{ | |
public static final O$ MODULE$; | |
public static {}; | |
public java.lang.Object tag(); | |
public O$(); | |
} | |
//BELOW WORKS BETTER | |
scala> object O { | |
| def tag[T, @specialized(scala.Int, scala.Long) U](u: U): U with Tagged[T] = u.asInstanceOf[U @@ T] | |
| } | |
defined module O | |
scala> :javap O | |
Compiled from "<console>" | |
public final class O$ extends java.lang.Object implements scala.ScalaObject{ | |
public static final O$ MODULE$; | |
public static {}; | |
public java.lang.Object tag(java.lang.Object); | |
public int tag$mIc$sp(int); | |
public long tag$mJc$sp(long); | |
public O$(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment