scala类型';提取';

scala类型';提取';,scala,types,type-systems,unboxing,Scala,Types,Type Systems,Unboxing,这可能不是最正确的术语,但我所说的盒式类型是类型T的Box[T]。因此,选项[Int]是一个装箱的Int 如何提取这些类型?我天真的尝试: //extractor type X[Box[E]] = E //doesn't compile. E not found //boxed type boxed = Option[Int] //unboxed type parameter = X[boxed] //this is the syntax I would like to achieve im

这可能不是最正确的术语,但我所说的盒式类型是类型
T
Box[T]
。因此,
选项[Int]
是一个装箱的
Int

如何提取这些类型?我天真的尝试:

//extractor
type X[Box[E]] = E //doesn't compile. E not found

//boxed
type boxed = Option[Int]

//unboxed
type parameter = X[boxed] //this is the syntax I would like to achieve
implicitly[parameter =:= Int] //this should compile

有没有办法做到这一点?除了Apocalisp博客,我很难找到Scala中类型级元编程的说明

我只能想象两种情况。如果使用类型参数,则如果使用更高级的类型,例如作为方法的参数,则其类型参数将在方法泛型中复制:

trait Box[E]

def doSomething[X](b: Box[X]) { ... } // parameter re-stated as `X`
或者您有类型成员,然后可以针对每个实例引用它们:

trait Box { type E }

def doSomething(b: Box) { type X = b.E }
…或一般而言

def doSomething(x: Box#E) { ... }

因此,我认为您需要根据您实际想要实现的目标来重写您的问题。

哪种情况下,您有更高的种类类型(您称之为“boxed”),但没有其类型参数?我无法想象您的
参数会出现或有用的任何场景?这更多的是对scala typesystem的探索,我没有任何用例