[Haskell-cafe] In-place modification

Donald Bruce Stewart dons at cse.unsw.edu.au
Sun Jul 15 06:48:46 EDT 2007


hughperkins:
> 
>    On 7/15/07, Donald Bruce Stewart <[1]dons at cse.unsw.edu.au>
>    wrote:
>    > [snip] unsafeWrite[snip]
>    > [snip]unsafeRead[snip]
>    Hi Donald, the idea is to use this for operational code, so
>    avoiding unsafe operations is preferable ;-)  You'll note
>    that the C# version is not using unsafe operations, although
>    to be fair that's because they worked out slower than the
>    safe version ;-)

"unsafe"' here just means direct array indexing. Same as the other
languages. Haskell's 'unsafe' is a little more paranoid that other
languages.

>    Also, the whole algorithm is bound to the IO Monad, which is
>    something I'd like to avoid if possible, since my entire
>    interest in Haskell stems from the possibilites of running
>    programs easily on 1 megacore processors in the future.

You're deciding that on a cache-thrashing primes benchmark?

Since the goal is to flip bits very quickly in the cache, you could
localise this to the ST monad then, as its perfectly pure on the
outside.

>    Anyway, congrats you got nearly as fast as C#!

Try the other version I just sent. This one trashes cache lines
needlessly.

What C# version are you using, by the way? (So I can check if it does
any tricks).

-- Don


More information about the Haskell-Cafe mailing list