Thanks Kim for your answer but as far as I understand strict evaluation should save in space as expression is not expanded in terms of thunks,but I can't understand time savings.Can you pls explain strict evaluation?<br><br>On Friday, December 11, 2015, Kim-Ee <<a href="mailto:ky3@atamo.com">ky3@atamo.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Have you tried BangPatterns? Compiled with optimization, I get 22 secs. Here's the full program:<br><br><span style="font-family:monospace,monospace">{-# LANGUAGE BangPatterns #-}<br><br>f :: Int -> Int -> Int<br>f !m !n <br> | m==0 = n+1<br> | n==0 = f (m-1) 1<br> | otherwise = f (m-1) (f m (n-1))<br><br>main = putStrLn (show (f 4 1))<br></span><br></div><div class="gmail_extra"><br clear="all"><div><div>-- Kim-Ee</div></div>
<br><div class="gmail_quote">On Fri, Dec 11, 2015 at 9:47 PM, Abhishek Kumar <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','abhishekkmr18@gmail.com');" target="_blank">abhishekkmr18@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I was trying to write below program for ackerman function but it fails (waits too long) for ack(4,1) whereas a recursive C program gives result in 37secs.Can someone pls explain this behaviour and recomend some optimisation.<div><div><br></div><div>------haskell code</div><div>f m n | m==0 =n+1</div><div> | n==0 = f (m-1) 1</div><div> | otherwise = f (m-1) (f m (n-1))</div><div><br></div><div>Thanks</div><span><font color="#888888"><div>Abhishek Kumar</div></font></span></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','Beginners@haskell.org');" target="_blank">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>
<br></blockquote></div><br></div>
</blockquote>