putting laziness back on the parallelized map

From: Sebastian Hanowski <sebastian.hanowski_at_web.de>
Date: Wed, 12 Mar 2008 14:10:24 +0100


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
                        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.

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

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
                        y,ys free

        -- PMAP> take 5 (tail (pmap' (div 5) [0..]))
        -- Result: [5,2,1,1,1] ? ;

curry mailing list
Received on Mi Mär 12 2008 - 16:37:03 CET

This archive was generated by hypermail 2.3.0 : Mo Dez 04 2023 - 07:15:10 CET