Scala找到List和SeqProjection,需要的时候Seq和Set
遇到以下错误:
TestCaseGenerator.scala:47: error: type mismatch;
found : List[(State, Seq.Projection[State])]
required: Seq[(State, Set[State])]
new LTS(Map(rndTrans: _*), Map(rndLabeling: _*))
^
one error found
不知道该怎么办。
rndTrans
初始化如下:
val rndTrans = for (s <- (0 to nStates).toList)
yield (new State(s) -> (for (s2 <- 0 to nStates
if prob(trans_probability))
yield new State(s2)))
更新:我碰巧使用的是 2.7 版本。
Sitting with the following error:
TestCaseGenerator.scala:47: error: type mismatch;
found : List[(State, Seq.Projection[State])]
required: Seq[(State, Set[State])]
new LTS(Map(rndTrans: _*), Map(rndLabeling: _*))
^
one error found
Can't figure out what to do about it.
The rndTrans
is initialized as follows:
val rndTrans = for (s <- (0 to nStates).toList)
yield (new State(s) -> (for (s2 <- 0 to nStates
if prob(trans_probability))
yield new State(s2)))
Update: I happen to be using version 2.7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当
toSet
方法(或toMap
)不可用时(因为运行的是旧版本的 scala 或者因为转换没有实现),通常可以应用一个以下方案。或
第一个版本使用
:_*
将集合转换为序列参数,然后调用新集合类型的构造函数方法。第二种方法创建了新类型的空集合,然后向其中添加 (++
) 旧集合。When a
toSet
method (ortoMap
) is not available (because one is running an older version of scala or because the conversion is just not implemented), one can often apply one of the following schemes.or
The first version uses the
:_*
to convert the collection to a sequence argument and then calls a constructor method of the new collection type. The second method created an empty collection of the new type and then adds (++
) the old collection to it.通常,
Seq
不是Set
。尝试将值序列转换为集合。Generally a
Seq
is not aSet
. Try converting the value sequence to a set.