[Haskell-cafe] I love purity, but it's killing me.
bertram.felgenhauer at googlemail.com
Sat Feb 9 09:49:08 EST 2008
Matthew Naylor wrote:
> Now, there remains the concern that Haskell's semantics does not
> enforce sharing. A Haskell compiler is free to change the sharing a
> program at a whim, unknowingly to the programmer who may be relying on
> it in for an efficient program. However, to my knowledge, it is an
> unwritten rule of Haskell compilers that sharing *is* preserved, and
> that they do perform *graph* reduction.
That is not true anymore for the threaded runtime of ghc. If two
threads demand the same thunk, one of them will usually block, but
there is a small window where both threads can start evaluting
the expression. To prevent this, you'd have to take a lock or
otherwise synchronize the threads upon entering each thunk, which
is prohibitively expensive.
See "Haskell on a Shared-Memory Multiprocessor",
for details, section 3.1 in particular.
More information about the Haskell-Cafe