用于scala中的表达式
Grr。。。我真的把头撞在桌子上,想知道为什么这样不行。能给我一些启发吗用于scala中的表达式,scala,for-loop,Scala,For Loop,Grr。。。我真的把头撞在桌子上,想知道为什么这样不行。能给我一些启发吗 type Occurrences = List[(Char, Int)] def generateSubsets( occ: Occurrences ): Occurrences = { if (occ.isEmpty) List() else { val firstChar = occ.head._1 val firstCharOcc: Int = occ.head._2
type Occurrences = List[(Char, Int)]
def generateSubsets( occ: Occurrences ): Occurrences = {
if (occ.isEmpty) List()
else {
val firstChar = occ.head._1
val firstCharOcc: Int = occ.head._2
val comb = for( i <- (1 to firstCharOcc); sp <- generateSubsets( occ.tail) )
yield (firstChar, i)::sp
comb.toList
}
}
一切都很顺利。错误是因为(i)的这一行
中的sp
val occ = List(('a', 5), ('b', 3), ('l', 2))
val t = ('m', 4)::occ
def test() = {
val i = 3
val occ = List(('a', 1), ('b', 2))
for( i <- (1 to i); sp <- ( occ) )
println(i, sp)
}
test()