3 ms·
Actually, today's hardware, with multiple cores/CPUs clashing over shared memory through non-shared cache, is less friendly to mutability than the old systems.
by jimwise 15y ago
Actually, today's hardware, with multiple cores/CPUs clashing over shared memory through non-shared cache, is less friendly to mutability than the old systems.
Immutability does require different data structures; a (singly-linked) list is easy to make immutable in most cases -- many lists with the same tail part can share that tail, without copying when a new list starts sharing that tail. Arrays, not so much.
- eru 15y agoThough to be fair, singly-linked lists are not useful for parallelism.
- danieldk 15y agoUnless the list elements can be thunks that can be evaluated when necessary or appropriate. See for instance Control.Parallel.Strategies in Haskell, which provides amongst others 'parMap' (parallel mapping over lists).
- eru 15y agoEven then it's not enough. The problem is that the structure of a list is itself linear. Guy Steele had a nice talk about that. (This only bites you when your lists get long.)
- danieldk 15y agoI think that's a too blanket statement. What do you want to do with the list, a map or a fold? In the former case, what is the cost of the function application?
- eru 15y agoPlease have a look at Guy Steele's talk (http://www.vimeo.com/6624203 http://www.vimeo.com/6624203). Basically he suggests using tree-like data structures, instead of linear data structures. You can also map, fold and filter over trees, but it parallelizes better.