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, Kim-Ee <ky3@atamo.com> wrote:
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 (m-1) 1
   | otherwise = f (m-1) (f m (n-1))

main = putStrLn (show (f 4 1))


-- Kim-Ee

On Fri, Dec 11, 2015 at 9:47 PM, Abhishek Kumar <abhishekkmr18@gmail.com> 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.

------haskell code
f m n  | m==0 =n+1
           | n==0 = f  (m-1) 1
           | otherwise = f (m-1) (f m (n-1))

Thanks
Abhishek Kumar

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners