Re:The compiler will optimize that away
by tom_mellior on Monday May 03, 2021 @09:51AM
(#27025057)
> Are you thinking of something else? That's an effect of call by value, but linked lists actually aren't good at that and you have to copy them to pass them around.
Are you thinking of something else? Haskell (and all other ML-family languages, and Lisps) lists are passed around by copying a single pointer to the head element. Different lists can share tail elements, i.e., elements can be members of more than one list.
All this is in contrast to Java-style linked lists, where there is a list object that controls its elements.
> Are you thinking of something else?
I think the point is to contrast them with dynamic arrays --- linked lists, unlike arrays, are persistent data structures, which does make them easier to reason about.
> Also, the common definition of a linked list has the list responsible for allocating each item
I'm not sure how this is relevant in the context of Haskell, given that it's garbage collected.
> That's an incredibly valuable feature for correctness and safety.
Are you thinking of something else? That's an effect of call by value, but linked lists actually aren't good at that and you have to copy them to pass them around. You need something like these to make it efficient:
https://en.wikipedia.org/wiki/Finger_tree
https://en.wikipedia.org/wiki/Read-copy-update