https://wiki.haskell.org/index.php?title=Shootout/Ack&feed=atom&action=history
Shootout/Ack - Revision history
2024-03-29T06:42:43Z
Revision history for this page on the wiki
MediaWiki 1.35.5
https://wiki.haskell.org/index.php?title=Shootout/Ack&diff=6691&oldid=prev
DonStewart: port
2006-10-08T01:29:34Z
<p>port</p>
<p><b>New page</b></p><div>A Shootout entry for the ackermann function<br />
<br />
== Code ==<br />
<br />
All the following entries have the same performance. The difference is<br />
loc. The idea is to beat the SML entry of 4 loc. Performance is already<br />
excellent.<br />
<br />
Interestingly, all run much faster when compiled with -fasm.<br />
<br />
== Proposal ==<br />
<br />
<haskell><br />
-- http://shootout.alioth.debian.org/<br />
-- shortened by Bryn Keller, Einar Karttunen and Don Stewart<br />
<br />
import System<br />
<br />
main = getArgs >>= \[n] -> putStrLn . (("Ack(3,"++n++"): ")++) . show . ack 3 $ read n<br />
<br />
ack (0::Int) (n::Int) = n+1<br />
ack m n = ack (m-1) $ if n == 0 then 1 else ack m (n-1)<br />
</haskell><br />
<br />
== Original entry ==<br />
<br />
7 loc<br />
<br />
<haskell><br />
{-# OPTIONS -O2 -fasm #-}<br />
-- $Id: ackermann-ghc.code,v 1.27 2006/01/08 22:44:56 igouy-guest Exp $<br />
-- http://shootout.alioth.debian.org/<br />
-- shortened by Bryn Keller and Einar Karttunen<br />
<br />
import System(getArgs)<br />
<br />
main = do ~[num] <- getArgs<br />
putStrLn ("Ack(3," ++ num ++ "): " ++ (show (ack 3 (read num))))<br />
<br />
ack :: Int -> Int -> Int<br />
ack 0 n = n+1<br />
ack m 0 = ack (m-1) 1<br />
ack m n = ack (m-1) (ack m (n-1))<br />
</haskell><br />
<br />
[[Category:Code]]</div>
DonStewart