-- Exercise in Eden programming: Hamming numbers -- -- The sequence of Hamming numbers consists of all multiples -- of 2, 3, and 5, in ascending order, without duplicates: -- { 2^i * 3^j * 5^k | i,j,k natural numbers} -- -- Observation (Dijkstra): -- 1) 1 is a Hamming number -- 2) If h is a Hamming number, 2*h, 3*h and 5*h are also -- Hamming numbers. -- ------------------------------------------------------------ import Control.Parallel.Eden hiding (merge) import System.Environment main :: IO () main = do args <- getArgs let n = if null args then 0 else read (head args) res = hamming!!n putStr ("Hamming number " ++ show n ++ " is " ++ show res ++ ".") hamming = let [h2,h3,h5] = error "create multiplication processes here" in 1 : error "merge results h2, h3, and h5 here" times :: Int -> Process [Int] [Int] times n = process (map (*n)) merge :: [Int] -> [Int] -> [Int] --merge [] bs = bs --merge as [] = as merge as@(a:ra) bs@(b:rb) = if a < b then a: merge ra bs else if a == b then a: merge ra rb else b: merge as rb mergeP :: Process ([Int],[Int]) [Int] mergeP = process (uncurry merge)