4 ms·
One problem is that functional programming style is often focused on recursion - not just in its functions, but also its data structures. Trees, linked lists a
by Athas 10y ago
One problem is that functional programming style is often focused on recursion - not just in its functions, but also its data structures. Trees, linked lists and graphs are GPU poison, while arrays map very well to the hardware. However, arrays don't have the pleasant recursive structure that allows you to encode nifty properties (and do pattern matching) the way that is popular in functional programming.
However, array programming is basically functional programming, and does map very well to parallel execution in general. While most array programming is nowadays of the fairly simple form you see in libraries like Numpy, older languages like APL show how far you can go. It's a somewhat alien style of programming to most modern programmers, though.
My rule of thumb: parallel programming is hard. Functional programming makes it trivial to make parallel programs that are correct, but they still might not be fast.
- infinite8s 10y agoIf those recursive structures are static then it's fairly easy to map them into an array form.
- vegabook 10y agoIs Rust the right way forward then? Functional enough without obsessing about linked-memory structures / recursion etc?
- Athas 10y agoI don't think so. Rust has excellent support for concurrency, but does not have any interesting parallel constructs. Which means that while it can probably be fine for coarse-grained multicore parallelism, it does not provide the fine-grain parallelism you need on something like a GPU.
- steveklabnik 10y agoNot built in, but there are libraries, like rayon or crossbeam.