Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于scala中的表达式_Scala_For Loop - Fatal编程技术网

用于scala中的表达式

用于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

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
        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()