0
 def balance(chars: List[Char]): Boolean = { if (chars.isEmpty == true) true else transCount(chars, 0) def transCount(chars: List[Char], pro: Int): Boolean = { var dif = pro chars match { case "(" :: Nil => false case ")" :: Nil => dif -= 1; if (dif == 0) true else false case _ :: Nil => if (dif == 0) true else false case "(" :: tail => dif += 1 transCount(tail, dif) case ")" :: tail => dif -= 1; if (dif < 0) false else transCount(tail, dif) case _ :: tail => transCount(tail, dif) } } } 

I have the type mismatch problem

Error:(30, 13) type mismatch; found : String("(") required: Char case "(" :: Nil => false ^ 

but really do not know how to fix (do not use char.toList please)

1
  • 3
    Char literals use single quotes so you need to use case '(' :: Nil => false ... instead. Commented Mar 28, 2015 at 19:06

1 Answer 1

5

chars is declared as a List[Char].

However, your first pattern is "(" :: Nil, which is a List[String] because "(" is a String - hence the type mismatch.

You need a character literal '(', not a String literal "("

The same applies to the other patterns, of course.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.