[Haskell-cafe] Make this code more idiomatic?

David Turner dct25-561bs at mythic-beasts.com
Tue Dec 29 09:55:07 UTC 2015


Hi,

I'd like to use the Control.Parallel.Strategies machinery to evaluate parts
of a big record-based data structure in the background. The following code
is the sort of thing that I've ended up with - it makes a spark that forces
the actuals field of a user object, in the sense that it forces all of the
elements to WHNF. (At least, that's what I hope it's doing!)

updateActuals user = runEval $ do
  newActuals <- rparWith (evalTraversable rseq)
              $ calculateActuals user
  return user { actuals = newActuals }

However, I'm concerned that runEval is marked as "for Strategy programmers"
and that I should be using some collection of combinators instead of
dropping down to this level. But I just can't work out how to combine the
available combinators to do the same thing. In particular, all the articles
I've found about this seem to end up adding `using` something to the end of
one key line of code to achieve near-perfect parallelisation, but now that
I come to do it myself I'm stuck! I think I'm looking for something like:

updateActuals user = user { actuals = newActuals } `using` ...

Can anyone help me fill in the blank there?

Many thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151229/0afb5153/attachment.html>


More information about the Haskell-Cafe mailing list