Commit d665bb10 authored by Simon Marlow's avatar Simon Marlow

update to work with weak sparks using the new Strategies

parent 30ee965e
-- -*- haskell -*- -- -*- haskell -*-
-- Time-stamp: <2008-10-22 10:13:48 simonmar> -- Time-stamp: <2010-05-25 16:25:18 simonmar>
-- --
-- ADT of a binary tree (values only in leaves). -- ADT of a binary tree (values only in leaves).
-- Parallel functions use par and seq directly. -- Parallel functions use par and seq directly.
...@@ -12,6 +12,7 @@ module Tree(Tree, ...@@ -12,6 +12,7 @@ module Tree(Tree,
force_tree, par_tree_map) where force_tree, par_tree_map) where
import Control.Parallel import Control.Parallel
import Control.Parallel.Strategies
infixl 2 ^: infixl 2 ^:
...@@ -25,14 +26,15 @@ tree_map f (Node left right) = Node (tree_map f left) (tree_map f right) ...@@ -25,14 +26,15 @@ tree_map f (Node left right) = Node (tree_map f left) (tree_map f right)
par_tree_map :: (Integral a, Integral b) => (a -> b) -> Tree a -> Tree b par_tree_map :: (Integral a, Integral b) => (a -> b) -> Tree a -> Tree b
par_tree_map f (Leaf x) = Leaf (f x) par_tree_map f (Leaf x) = Leaf (f x)
par_tree_map f (Node left right) = force_tree left' `par` par_tree_map f (Node left right) =
(force_tree right' `pseq` Node (par_tree_map f left) (par_tree_map f right) `using` partree
(Node left' right')) where
-- parentheses added because partree (Node l r) = do
-- some versions of GHC have the l' <- (rpar `dot` rtree) l
-- wrong fixity for par & pseq r' <- rtree r
where left' = par_tree_map f left return (Node l' r')
right' = par_tree_map f right
rtree t = force_tree t `pseq` Done t
-- force evaluation of tree (could use Strategies module instead!) -- force evaluation of tree (could use Strategies module instead!)
force_tree :: (Integral a) => Tree a -> () force_tree :: (Integral a) => Tree a -> ()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment