斯卡拉发现列表和SeqProjection,需要序列和设置时
题
用下面的错误坐在:
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 强>
。解决方案
当一个toSet
方法(或toMap
)不可用(因为一个正在运行阶的旧版本或因为转换只是未实现),经常可以应用以下方案中的一种。
val collection: Seq[SomeType] = ...
Set( collection: _* )
或
Set() ++ collection
在第一版本使用:_*
到集合转换为序列参数,然后调用新的集合类型的构造方法。第二种方法所创建的新类型的空集,然后添加(++
)旧的集合到它。
其他提示
一般一个Seq
不是Set
。尝试值序列转换为一组。
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)).toSet)
不隶属于 StackOverflow