4 ms·
Here is a parallel map in Haskell pmap f xs = map f xs `using` parList rdeepseq The cool thing about this is that `map` is just the regular map function.
by wz1000 12y ago
Here is a parallel map in Haskell
pmap f xs = map f xs `using` parList rdeepseq
The cool thing about this is that `map` is just the regular map function. However, as Haskell is lazy, `map f xs` returns a thunk and is not immediately evaluated. `using` allows you to evaluate the resultant thunk using any "evaluation strategy", and `parList rdeepseq` describes a strategy for evaluating lists in parallel!
Also, like the Erlang VM, GHC has fast, lightweight "green threads".
Edit: Another way to write it would be
pmap _ [] = []
pmap f (x:xs) = runEval $ do
x' <- rpar (f x)
xs' <- rpar (pmap f xs)
return $ (x':xs')