getPara :: (Num [Char]) => [Char] -> Integer -> [Char]
getPara "" _ = ""
getPara str nr
| (nr == 0 ) && ((head str) == ')' ) = ')' : getPara "" 0
| ( nr == 0 ) && ( (head str) == '(' ) = '(' : (getPara (tail str) 0)
| (nr /= 0 ) && ( (head str) == '(') = (getPara (tail str) nr-1)
| (nr == 0 ) && ( (head str) /= '(' ) = (head str) : (getPara (tail str) 0 )
| otherwise = (getPara (tail str) nr)
What I am trying to do is to get from a String the nr set of brackets and the error I get is:
Illegal Haskell 98 class constraint in type declaration
*** Expression : getPara
*** Type : Num [Char] => [Char] -> Integer -> [Char]
What is the problem?
Your type signature for
getParais not allowed, but the underlying problem is that you’re missing parentheses somewhere deep in the definition. If your change your code to:it compiles … but I’m not sure if it works.
There were two changes:
getParasurround
nr-1in parentheses in