0
votes

I'm having type mismatch in the end line of code

 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
1
Did you paste-and-copy correctly? It does not make much sense. - toto2
balance expects Boolean as a return value, but you only defined f and did nothing else in balance - Victor Moroz
@VictorMoroz You should elaborate on this as an answer below, because it's certainly correct. - joescii
see this answer, it's exactly the same situation. - Infinity

1 Answers

1
votes

balance expects Boolean as a return value, but you only defined f and did nothing else in balance. What missing is probably f(chars, 0) as the last statement in balance.