English 中文(简体)
我怎么会hang一.一umi。 取舍?
原标题:How do I hang onto an izumi.reflect.Tag?

我先使用<代码>izumi.reflect。 Tag 用于对电动进行控制,其作用很大。 除非在某个时候我失去这种信息,否则我不敢肯定如何回头。 在此,我想做的是:

case class Rule[T: Tag](lhs: String, rhs: Repr[T])

这是巨大的。 www.un.org/spanish/ecosoc 了解其中的<代码>rhs的类型。 例外

val rules: List[Rule[?]] = // some list of rules
rules.foreach { r =>
  process(r)
}

def process[T: Tag](rule: Rule[T]): Unit = // side-effectful processing

此时此刻,我拿到<代码>,不能为iz蒸而找到含蓄的价值。 Tag[T]。 OK没有大的意外。 该<代码>Tag可回收,因为它与<代码>中所有其他标签混在一起。 名单/编号。 但是,我能否拯救各方,使之在晚些时候回头?

我受审

case class Rule[T: Tag](lhs: String, rhs: Repr[T]):
   val LightTypeTag = Tag[T].tag

和在<代码>上的类似方式 达格·哈马舍尔德图书馆

process(r, r.tag)

def process[T: Tag](rule: Rule[T], tag: Tag[T]) = ...

或明确通过<条码>Tag[T] 加入<条码>方法,但我可以说明如何做以下任何工作:

  1. Save a value of type Tag[T].
  2. Convert a value of type LightTypeTag back to a Tag[T].
  3. Some other combination of explicit saving and using some other values that will make this type check.

任何帮助都得到高度赞赏。

问题回答

OK. Of course, after I posted this, I think I got an answer, but I d like to be sure it s the right one. I realized I really wanted a Tag[T] and I couldn t figure out how to get one, but then I realized that I had a given Tag[T] available, so I did

case class Rule[T: Tag](lhs: String, rhs: Repr[T]):
  val tag: Tag[T] = summon[Tag[T]]

and if I add (using rule.tag) in the places where I m missing the implicit Tag[T], things seem to work. Is this the right way to handle this?





相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签