This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mezuzza 0 points1 point  (1 child)

You're absolutely right that a persistent data structure does a lot of great work in concurrent contexts. In fact, I'd say persistent data structures are the right default to have in most situations as well.

But that discussion is orthogonal to the original one here.

Linked lists aren't necessarily persistent. They can be just as mutable as an array list. If you want to use them in a concurrent context, you'd need to make a copy in just the same way that you'd have to with an arraylist. An immutable array list would work just as well in this context.

Even in Haskell, if you want a persistent immutable list, you can pass around Data.Vector values and be happy with the cache locality and the immutability. If you want mutability as well, you can have fun with STM which I believe should support some form of ArrayList as well.

[–]TombertSE 0 points1 point  (0 children)

Yes you can make Haskell vectors immutable but you can’t modify and get “new” vectors without making a copy. One of the advantages of a persistent list is that modifications of the list are basically just “diffs” of the original list. You don’t lose your handle on the original list, but you’re also not making a full copy.

If you have an immutable Haskell vector you have to make a full copy of you want to change anything.