<div dir="ltr">The spirit of declarative programming lies in the fact that you try to just tell the compiler what something means. Instead of thinking about keeping track of the numbers of parentheses, and then applying them afterwards, I would suggest you create a function to do the same job:<div><br></div><div><font face="monospace, monospace">    bracketed :: String -> String</font></div><div><font face="monospace, monospace">    bracketed s = "(" ++ s ++ ")"</font></div><div><br></div><div>This would allow you to remove the numeric argument, and also write cleaner code.</div><div><br></div><div>The second thing that you can improve is the pattern matching. You can use <a href="http://hackage.haskell.org/package/base-4.8.1.0/docs/Data-List.html#v:isPrefixOf">isPrefixOf</a> to check functions, or use a take inside a case statement to get cleaner handling of different cases.</div><div><br></div><div><font face="monospace, monospace">    case take 3 str of</font></div><div><font face="monospace, monospace">      "sin" -> ...</font></div><div><font face="monospace, monospace">      "cos" -> ...</font></div><div><font face="monospace, monospace">       _ -> ...</font></div><div><font face="monospace, monospace"><br></font></div>This would also let you debug your code more easily, just as you require.</div><div class="gmail_extra"><br><div class="gmail_quote">On 4 November 2015 at 14:51, Imants Cekusins <span dir="ltr"><<a href="mailto:imantc@gmail.com" target="_blank">imantc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> a function that is supposed to add parenthesis to sin/cos expressions.<br>
</span>a) Sin 5 + 3        ->    Sin(5) + 3<br>
b) Sin Cos (5+3)   ->    Sin (Cos(5+3))<br>
c) Sin Cos 5 * 3   ->    Sin(Cos(5)) * 3<br>
<br>
are you looking for textual representation or actual Haskell code which runs?<br>
if actual code, these examples may be re-written like this:<br>
a) sin 5 + 3<br>
b) sin $ cos $ 5 + 3<br>
c) sin (cos 5) * 3<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>