
Hello! I've written a function that is supposed to add parenthesis to sin/cos expressions. For example - Sin5+3 -> Sin(5) + 3 - SinCos(5+3) -> Sin(Cos(5+3)) - SinCos5 * 3 -> Sin(Cos(5)) * 3 The problem is that it converts the following expression *SinSin(5+1+2)* into *Sin(Sin(5)+1+2)* Could someone point me to the direction of a solution to this? Thanks in advance! convert :: String -> String convert s = convert' s 0 convert' :: String -> Int -> String convert' [] n = replicate n ')' convert' (a:as) n | ((a == 'n' || a == 's') && ((take 1 as) /= "(")) = a : "(" ++ (convert' as (n+1)) | ((a == '+' || a == '*') && (n > 0)) = (replicate n ')') ++ [a] ++ (convert' as 0) | otherwise = a : (convert' as n)