Scala found List and SeqProjection, when required Seq and Set
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.
When a toSet
method (or toMap
) 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.
val collection: Seq[SomeType] = ...
Set( collection: _* )
or
Set() ++ collection
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.
Generally a Seq
is not a Set
. Try converting the value sequence to a 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)
精彩评论