Hello Haskell-Cafe!

I've read about Control.Parallel and wanted to give it a try. Here's what I wrote:

-----------
import Control.Parallel
import Data.List

splitList :: [Integer] -> [[Integer]]
splitList = unfoldr f where
    f [] = Nothing
    f ~x = Just (splitAt 30000 x)

map' :: (a->b) -> [a] -> [b]
map' f (x:xs) =fx `par` (seq mfxs (fx:mfxs)) where
    fx = f x
    mfxs = map' f xs
map' f [] = []

product' :: [Integer] -> Integer
product' = foldr1 (\x y -> seq x (x*y))

fak :: Integer -> Integer
fak n = product' $ map' product' (splitList [1..n])

main = putStrLn $ seq (fak 1000000) "done"
-----------

This computes 1000000!. This version takes 8m29.189s to execute. Replace foldr1 with foldr and that goes down to 7m4.315s. Replace product' with the Prelude product and it takes only 6m17.685s. Why is that so? I'm using ghc 6.8.1 on Mac OS X.

Regards,

Adrian

Attachment: PGP.sig
Description: Signierter Teil der Nachricht

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

Reply via email to