[Haskell-cafe] Fibbonachi numbers algorithm work TOO slow.

gitulyar gitulyar at gmail.com
Mon Nov 5 17:22:25 EST 2007


Please help me. I'm new in Haskell programming, but wrote some things in
Scheme. I make so function:

fib 1 = 1
fib 2 = 2
fib n = fib (n-1) + fib (n-2)

And when I call "fib 30" it works about 5 seconds. As for me it's really TOO
SLOW.

Tell me please if I have something missed, maybe some compiler
(interpretaitor) options (I use ghc 6.6.1).

P.S. As I understand function "fib n" should be calculated one time. For
example if I call "fib 30" compiler builds tree in which call function "fib
28" 2 times and so on. But as for lazy calculation principle it should be
calculated just ones and then it's value is used for all other calls of this
function with the same argument. But it seems that this principle doesn't
work in this algorithm.
-- 
View this message in context: http://www.nabble.com/Fibbonachi-numbers-algorithm-work-TOO-slow.-tf4752338.html#a13589051
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list