【发布时间】:2015-06-22 11:09:18
【问题描述】:
在一些其他语言的函数式编程经验之后,我刚刚开始学习 Scala。
def freq(c:Char, y:String, list:List[(Char,Int)]): List[(Char,Int)] = list match{
case _ => freq(c, y.filter(_ == c), list :: List((count(c,y),c)))
case nil => list
}
在上面的代码中,我在尝试递归连接列表时遇到错误。错误发生在list::List((count(c,y),c))。 count 方法接受一个 char 和一个字符串,并根据该 char 出现的次数返回一个 int。
任何帮助将不胜感激。我得到状态的错误发现 [(Char,Int)] 需要 (Char,Int)。
【问题讨论】:
标签: scala recursion case frequency