Contents of Glasgow-haskell-users Digest, Vol 17, Issue 8

Jost Berthold berthold at Mathematik.Uni-Marburg.de
Tue Jan 18 07:10:39 EST 2005


Hi Bill,

In order to force the *complete* evaluation of your result, you
could use Evaluation Strategies. Strategies are a concept
introduced for increasing parallelism in Glasgow parallel Haskell.
Parallelism and lazy evaluation are in a way contrary aims, since you
want your parallel evaluation to start ASAP, even if there is no
actual demand on its result.
Check the following paper for more information:
http://www.macs.hw.ac.uk/~dsg/gph/papers/html/Strategies/strategies.html

A strategy module should be included in the libraries in GHC...
Formerly just module "Strategies" in package concurrent,
now in package base, module "Control.Parallel.Strategies"

Concretely, I suggest to apply the strategy "rnf" (reduce to normal form)
to "junk" instead of just checking the first node in the graph.
What null does is to look at the list and yields true if the top constructor is 
"[]" and not "(:)".
Your version below is what you get with  just "junk `seq` runNReps f x (todo-1)"
- weak head normal form evaluation.

runNReps f x todo | todo > 0 = do let junk = f x
                                   rnf junk `seq` runNReps f x (todo-1)
HTH
Jost

glasgow-haskell-users-request at haskell.org wrote:

Message: 7 Date: Mon, 17 Jan 2005 14:21:00 -0600
From: "jekwtw" <jeaniek7 at comcast.net>
Subject: Re: Timing Functions
To: <glasgow-haskell-users at haskell.org>
Message-ID: <003401c4fcd2$1009b5a0$94a92942 at WOOD2441FMASZ8>
Content-Type: text/plain; charset="iso-8859-1"

Many thanks to both Georg and Lemmih. Actually, I had considered laziness, but I 
didn't pursue it enough. I tried one version of runNReps in which I passed (f x) 
as an additional arg; when that didn't work, a little thought convinced me that 
laziness was doing me in. I also tried another approach, which was to "use" the 
function evaluation, but that didn't work either (note: I know (f x) can not be 
the empty list for values of x I'm interested in, but I don't think Haskell 
does, unless it's *really* smart :-) :

 >> runNReps :: (Int -> [a]) -> Int -> Int -> IO ()
 >> runNReps f x todo
 >>             | todo > 0 = do let junk = (f x)
 >>                                     if null junk then return (()) else 
runNReps f x (todo - 1)
 >>             | otherwise = return (())

Ideas?

Again, many thanks,

  -- Bill Wood
     bill.wood at acm.org





More information about the Glasgow-haskell-users mailing list