Strict<->Lazy?

Siegfried Gonzi siegfried.gonzi@kfunigraz.ac.at
Thu, 01 Jul 1999 09:44:14 +0200


 
> I have read your contribution to this list, and was surprised that it took
> Clean 30 seconds to compute the 40-th Fibonacci number. I thought that was
> impossible, so I wrote a tiny program to check. To my astonishment you
> were right when using a simple Fibonacci algorith, like
> 
> fib :: Int -> Int
> fib 0 = 0
> fib 1 = 1
> fib n = fib (n-1)+fib(n-2)
> 
> This took my computer about 21.5 seconds to calaculate the 40-th number.
> But when rewriting the algorithm to
> 
> fib2 :: Int -> Int
> fib2 n = fibList !! n
> where
>   fibList = [0,1:[i+j \\ i <- fibList & j <- tl fibList]]
> 
> the computing time became negligible. When changing the output to reals
> even the 1000-th fibonacci number took virtually no time to compute.
 

Thank you very much. Now I think it is worth to study the book about
Clean (draft version) in detail. 


Greetings,
Siegfried Gonzi