Created
January 4, 2016 21:33
-
-
Save clojj/7ec5107181fccd5f784e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Parallel | |
| import Data.List | |
| pfold :: (Num a, Enum a) => (a -> a -> a) -> [a] -> a | |
| pfold _ [x] = x | |
| pfold mappend xs = (ys `par` zs) `pseq` (ys `mappend` zs) where | |
| len = length xs | |
| (ys', zs') = splitAt (len `div` 2) xs | |
| ys = pfold mappend ys' | |
| zs = pfold mappend zs' | |
| main = print $ pfold (+) [ foldl' (*) 1 [1..x] | x <- [1..5000] :: [Integer]] | |
| -- need a more complicated computation than (+) of numbers | |
| -- so we produce a list of products of many numbers | |
| -- ghc -O2 -threaded a.hs | |
| -- a +RTS -N1 -s | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment