How can I solve this type mismatch in Scala? -


 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 type mismatch problem

error:(30, 13) type mismatch;  found   : string("(")  required: char        case "(" :: nil => false             ^ 

but not know how fix (do not use char.tolist please)

chars declared list[char].

however, first pattern "(" :: nil, list[string] because "(" string - hence type mismatch.

you need character literal '(', not string literal "("

the same applies other patterns, of course.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -