简体   繁体   中英

How to write Haskell array strategies

I want to write a strategy to evaluate items in an array in parallel. The old strategies had parArr to do this ( see here ). But this is not found in the new Control.Parallel.Strategies module.

Eg parallel list evaluation: map f myList `using` parList rdeepseq

I would want to be able to do something like: amap f myArr `using` parArr rdeepseq , where amap is from Data.Array.Base and applies a function to each of the elements (sequentially).

The following seems to work but I wonder if it is doing it right, and want to know how I could define my own parArr .

This works: amap ((+1) `using` rpar) $ Array.array (0,4) [(0,10),(1,20),(2,30),(3,40),(4,50)]

For a previous question , I wrote a parallel evaluation strategy for the vector package. That should be a good place to start. You can see the code on hackage in the vector-strategies package.

I don't have time to give a full answer - perhaps I'll edit this later. Feel free to comment with extra questions and direction.

Apart from all the good advice given: The reason that there is no parArr anymore is simply that it has been replaced by the more general parTraversable . Just say:

amap f myArr `using` parTraversable rdeepseq

That should give you the behavior you asked for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM