[Haskell-cafe] Can't seem to get `par` working appropriately
with lists
Jules Bean
jules at jellybean.co.uk
Thu Feb 21 07:17:29 EST 2008
Luke Andrew wrote:
> import Control.Parallel
>
> fib1 n = if n == 0 then 0 else if n == 1 then 1 else fib1 (n-1) +
> fib1 (n-2)
> fib2 n = if n == 0 then 0 else if n == 1 then 1 else fib2 (n-1) +
> fib2 (n-2)
>
> main = do print $ (fib2 37 `par` fib1 37) + (fib2 37)
"fib2 37" won't be shared.
You're telling ghc to calculate fib2 37 once, in parallel, throw it
away, and then calculate it again.
Try:
let f1 = fib1 37
f2 = fib2 37
in print $ (f2 `par` f1) + f2
Jules
More information about the Haskell-Cafe
mailing list