[Haskell-cafe] Re: Why can't Haskell be faster?

Jules Bean jules at jellybean.co.uk
Wed Oct 31 11:06:04 EDT 2007

Robin Green wrote:
> On Wed, 31 Oct 2007 14:17:13 +0000
> Jules Bean <jules at jellybean.co.uk> wrote:
>> Specifically, clean's uniqueness types allow for a certain kind of 
>> zero-copy mutation optimisation which is much harder for a haskell 
>> compiler to automatically infer. It's not clear to me that it's
>> actually worth it, but I think that's the point at issue. I can
>> *imagine* algorithms in which copying is actually faster than
>> mutation, if copying gives you better locality.
> If you want in-place update in Haskell, you can use the ST monad, or
> IORefs. Yes, you have to refactor code, but anecdotally, uniqueness
> types aren't without problems either - you can make one small change
> and your code no longer satisfies the uniqueness condition.

IORefs don't give you in-place update.

They give you mutation, but new values are still allocated in new heap.

foo <- newIORef "hi"
writeIORef foo "bye"

-- "bye" is a new string, allocated in new heap. the only thing that got
-- mutated was a pointer.

STArrays and certain IO Arrays give you in-place update, though.


More information about the Haskell-Cafe mailing list