4 ms·
Maybe one of you functional gurus can answer this - One of the problems I have with functional programming is how do you handle multiple data structures on a si
by chadcmulligan 5y ago
Maybe one of you functional gurus can answer this - One of the problems I have with functional programming is how do you handle multiple data structures on a single thing. For example - say you have a drawing program, with say just one shape - a square. Now to make it fast when the user clicks somewhere you'd have a data structure like a k-d tree that can find your shape quickly. Now you also have another structure a list of the shapes, because you don't want to put them in the k-d tree, you update both structures when shapes change. You'd also want other structures for say undo/redo. I can't see anyway to do this in functional programming. Same applies to database style programming.
- hvocode 5y agoThat’s not that hard in an FP language. I routinely write code with multiple structures referring to the same thing. My usual solution is to have an identifier for the thing that indexes into an array or map, and then the other structures contain that ID instead of the object itself. It’s basically a pointer like I’d use in any other language. The details and choices for how to represent the IDs and structures is usually application specific, but that’s true in any language: how you do something should be the choice that best fits your problem. There isn’t anything about functional programming that makes it impossible or particularly difficult.
- chadcmulligan 5y agook, cool, would you know some sample code somewhere you could point me to? Just to see an example, always thought you couldn't do this.
- yawaramin 5y agoHow do you do it in whatever paradigm you use? It's probably very similar in FP, just the technical implementation is different.