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.
haskell code f m n  m==0 =n+1  n==0 = f (m1) 1  otherwise = f (m1) (f m (n1)) Thanks Abhishek Kumar _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgibin/mailman/listinfo/beginners 
Graham Hutton's paper "A tutorial on the expressiveness and universality of folds", provides a good introduction to folds, and implements the Ackerman function as an example. Folds were the first stumbling point for me when learning Haskell, and this paper helped me a lot. On 11 December 2015 at 20:17, Abhishek Kumar <[hidden email]> wrote: 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. Sumit Sahrawat, Junior  Mathematics and Computing, Indian Institute of Technology  BHU, Varanasi, India _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgibin/mailman/listinfo/beginners 
Administrator

In reply to this post by Abhishek Kumar
Have you tried BangPatterns? Compiled with optimization, I get 22 secs. Here's the full program: {# LANGUAGE BangPatterns #} f :: Int > Int > Int f !m !n  m==0 = n+1  n==0 = f (m1) 1  otherwise = f (m1) (f m (n1)) main = putStrLn (show (f 4 1))  KimEe On Fri, Dec 11, 2015 at 9:47 PM, Abhishek Kumar <[hidden email]> wrote: 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. _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgibin/mailman/listinfo/beginners 
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?
On Friday, December 11, 2015, KimEe <[hidden email]> wrote:
_______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgibin/mailman/listinfo/beginners 
Administrator

On Sat, Dec 12, 2015 at 4:19 PM, Abhishek Kumar <[hidden email]> wrote: 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? What happens to original program that has a sprawling mass of thunks all over RAM? The CPU spends most of its time waiting on the memory bus. And that's not even going into things like diskbacked virtual mem.  KimEe _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgibin/mailman/listinfo/beginners 
In reply to this post by KimEe Yeoh
Compiling below code (ghc make) still doesn't gives result on my i3 Ubuntu 64bit machine.Can u please elaborate optimisations you did?
Thanks Abhishek
On Friday, December 11, 2015, KimEe Yeoh <[hidden email]> wrote:
_______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgibin/mailman/listinfo/beginners 
with 'ghc O2' this takes 14 seconds on my macbook pro.
Dimitri On 12/12/15 10:35 AM, Abhishek Kumar
wrote:
Compiling below code (ghc make) still doesn't gives result on my i3 Ubuntu 64bit machine.Can u please elaborate optimisations you did? _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgibin/mailman/listinfo/beginners 
In reply to this post by Sumit Sahrawat, Maths & Computing,
IIT (BHU)
Sumit Sahrawat, Maths & Computing, IIT (BHU) writes: > Graham Hutton's paper "A tutorial on the expressiveness and universality of > folds", provides a good introduction to folds, and implements the Ackerman > function as an example. > Folds were the first stumbling point for me when learning Haskell, and this > paper helped me a lot. To save others from a search: http://www.cs.nott.ac.uk/~pszgmh/fold.pdf /M  Magnus Therning OpenPGP: 0x927912051716CE39 email: [hidden email] jabber: [hidden email] twitter: magthe http://therning.org/magnus Failure is not an option. It comes bundled with the software. _______________________________________________ Beginners mailing list [hidden email] http://mail.haskell.org/cgibin/mailman/listinfo/beginners signature.asc (815 bytes) Download Attachment 
Free forum by Nabble  Edit this page 