[Haskell-cafe] a parallel mapM?

Alexander Solla alex.solla at gmail.com
Fri Sep 28 22:48:46 CEST 2012

On Fri, Sep 28, 2012 at 11:01 AM, Greg Fitzgerald <garious at gmail.com> wrote:
> I also tried Control.Parallel.Strategies [2].  While that route works,
> I had to use unsafePerformIO.  Considering that IO is for sequencing
> effects and my IO operation doesn't cause any side-effects (besides
> hogging a file handle), is this a proper use of unsafePerformIO?

That's actually a perfectly fine use for unsafePerformIO, since the IO
action you are performing is pure and therefore safe (modulo your file
handle stuff).

unsafePerformIO is a problem when the IO action being run has side effects
and their order of evaluation matters (since unsafePerformIO will cause
them to be run in an "unpredictable" order)

One common use for unsafePerformIO is to run a query against an external
library.  It has to be done in the IO monad, but it is a "pure" computation
insofar as it has no side-effects that matter.  Doing this lets us promote
values defined in external libraries to bona fide pure Haskell values.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120928/4003dd93/attachment.htm>

More information about the Haskell-Cafe mailing list