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.

Regards,
    Malcolm

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to