[Haskell-cafe] Can Haskell outperform C++?

Simon Marlow marlowsd at gmail.com
Tue May 8 14:41:26 CEST 2012

On 06/05/2012 07:40, Janek S. wrote:
> a couple of times I've encountered a statement that Haskell programs
> can have performance comparable to programs in C/C++. I've even read
> that thanks to functional nature of Haskell, compiler can reason and
> make guarantess about the code and use that knowledge to
> automatically parallelize the program without any explicit
> parallelizing commands in the code. I haven't seen any sort of
> evidence that would support such claims. Can anyone provide a code in
> Haskell that performs better in terms of execution speed than a
> well-written C/C++ program? Both Haskell and C programs should
> implement the same algorithm (merge sort in Haskell outperforming
> bubble sort in C doesn't count), though I guess that using
> Haskell-specific idioms and optimizations is of course allowed.

On the subject of parallelism in particular, there is no fully implicit
parallelism in Haskell at the moment.  When people ask about this I
typically point to this paper:


which shows that it is possible to get some gains doing this, but it is
hard and the gains were not great.

However, what Haskell does give you is a guarantee that you can safely
call any function in parallel (with itself or with something else), as
long as the function does not have an IO type.  This is about as close
to automatic parallelisation as you can practically get.  Take any pure
function from a library that someone else wrote, and you can use it with
parMap or call it from multiple threads, and reasonably expect to get a
speedup.  Furthermore with parMap you're guaranteed that the result will
be deterministic, and there are no race conditions or deadlocks to worry


More information about the Haskell-Cafe mailing list