A: Evaluation order, ghc versus hugs, lazy vs. strict

Hal Daume III hdaume@ISI.EDU
Fri, 23 Aug 2002 05:10:05 -0700 (PDT)


I think there's more to strategies than this.  They are not necessarily
related to parallel programming and can be used for tuning (in the seq
sense) "sequential" (perhaps "non-parallel" would be a better
word) programs.

The type of strategies is:

  type Strategy a = a -> ()

for example, a strategy which reduces its argument to weak head normal
form could be given by:

  stratWHNF x = x `seq` ()

We define a funciton 'using' which uses strategies to do a computation:

  v `using` s = s x `seq` x

These are used in parallel programming something like:

  fib 0 = 1
  fib 1 = 1
  fib n = a + b `using` strategy
    where a = fib (n-1)
          b = fib (n-2)
          strategy result = a `par` b `par` result

This clearly separates the computation "a+b" from the way it is evaluated
"a in parallel to b in parallel to the result (i.e., a+b)".

But this can of course be used for sequential programming, too, simply by
using seq instead of par in the above example.  This enables you to write
clean code (your functions stay the same, except they are appended with
`using` strategy), but you can control more precisely when things get
reduced.

 - Hal

--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume

On 23 Aug 2002, Ketil Z. Malde wrote:

> Jan Kybic <kybic@ieee.org> writes:
> 
> > What are GUM and Strategies? Could you provide any links?
> 
>   http://www.cee.hw.ac.uk/~dsg/gph/docs/Gentle-GPH/sec-gph.html
> 
> GUM is an implementation of GPH (a parallel Haskell) that
> runs on top of PVM.
> 
> Strategies are about making sure parallel threads actually do the work
> they're intended to before returning control to the main thread; in
> other words, ensuring sufficient strictness.  Or something like that.
> 
> Grain of salt as applicable, I'm not using any of this yet.
> 
> -kzm
> -- 
> If I haven't seen further, it is by standing in the footprints of giants
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
>