Re: putting laziness back on the parallelized map

From: Wolfgang Lux <wlux_at_uni-muenster.de>
Date: Thu, 13 Mar 2008 17:05:31 +0100

Sebastian Hanowski wrote:

> I think I once saw this program on an old set of slides by Michael
> Hanus
>
> pmap :: (a -> b) -> [a] -> [b]
> pmap _ [] = []
> pmap f (x:xs) | y =:= f x & ys =:= pmap f xs = y : ys
> where
> y,ys free
>
> implementing a /parallel map/ for lists. I always liked this
> program
> since functorial mapping is treated as happening in parallel. But
> as I
> learn the equality constraint in Curry is strict such that this
> program
> forces the evaluation of the head and the tail of the resulting
> list.
> Which could be against intuition in a lazy language.

Sure, but then the idea of a parallel map is also against the intuition
of a lazy language, since it indeed forces the evaluation of the head
and
the tail of its argument list.

> When I tried to get a bit aquainted with how /function
> patterns/ are
> realised in Curry, I learned that there's now also a non-strict
> equality
> constraint.
>
> Maybe this could also be used to combine the lazy with the
> parallel
> evaluation behaviour allowing to map over infinite lists with
> partially
> defined elements.
>
> pmap' :: (a -> b) -> [a] -> [b]
> pmap' _ [] = []
> pmap' f (x:xs) | y =:<= f x & ys =:<= pmap' f xs = y : ys
> where
> y,ys free
>
> -- PMAP> take 5 (tail (pmap' (div 5) [0..]))
> -- Result: [5,2,1,1,1] ? ;

With your pmap' definition, the spine of the result list could be
constructed
concurrently, but the elements of the list are not evaluated
concurrently. In
fact they are not evaluated at all:
  PMAP> length (take 5 (pmap' (const failed) [0..]))
  Result: 5 ?

Regards
Wolfgang

_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Thu Mar 13 2008 - 17:16:41 CET

This archive was generated by hypermail 2.3.0 : Mon Nov 18 2019 - 07:15:06 CET