[Haskell-cafe] Typo or on purpose?
malcolm.wallace at me.com
Mon Aug 9 10:19:38 EDT 2010
On 8 Aug 2010, at 20:23, Alexander Kotelnikov wrote:
> This + 1 in (n1 + n2 + 1) what is it doing there?
> import Control.Parallel
> nfib :: Int -> Int
> nfib n | n <= 1 = 1
> | otherwise = par n1 (pseq n2 (n1 + n2 + 1))
> where n1 = nfib (n-1)
> n2 = nfib (n-2)
The nfib function, by convention, counts the number of function calls
needed in an evaluation of the fibonacci number, rather than
evaluating the fibonacci number itself. Hence the +1.
More information about the Haskell-Cafe