[Haskell-beginners] Haskell code optimisation
Dimitri DeFigueiredo
defigueiredo at ucdavis.edu
Sat Dec 12 12:57:11 UTC 2015
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?
> Thanks
> Abhishek
>
> On Friday, December 11, 2015, Kim-Ee Yeoh <ky3 at atamo.com
> <mailto:ky3 at 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 at gmail.com
> <javascript:_e(%7B%7D,'cvml','abhishekkmr18 at 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 at haskell.org
> <javascript:_e(%7B%7D,'cvml','Beginners at haskell.org');>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151212/8e52f93f/attachment.html>
More information about the Beginners
mailing list