2013-09-21 158 views
0

我有类型不匹配的代码到底线类型不匹配Scala中

def balance(chars: List[Char]): Boolean = { 

def f(chars: List[Char], count: Int) :Boolean= 
    if(chars.isEmpty) {(count==0)} 

     else if (chars.head == '(') f(chars.tail,count+1) 
     else if(chars.head == ')') f(chars.tail,count-1) 
     else f(chars.tail,count) 

} //Type mismatch; found: unit required Boolean 
+0

您是否正确粘贴并复制?这没有多大意义。 – toto2

+2

'balance'预计'Boolean'作为返回值,但您只定义了'f'并且没有在'balance'中做任何其他操作。 –

+0

@VictorMoroz您应该在下面详细说明这个问题,因为它当然是正确的。 – joescii

回答

1

balance预计Boolean作为返回值,但你只定义fbalance什么也不做。缺少的可能是f(chars, 0)作为balance中的最后一个陈述。