<div>Hello,<br><br>imagine the following situation: You want to implement e.g. Dijkstra's algorithm to find a shortest path between nodes u and v in a graph. This algorithm relies heavily on mutating arrays, so the type signature would look something like<br>
<br>getDistance :: Graph -> Node -> Node -> IO Int<br><br>Not mutating the underlying arrays would probably result in poor performance. BUT: For a constant graph, the distance between two nodes stays the same all the time, so in fact getDistance should be a pure function! <br>
So here is my question: Is there a way to write functions in Haskell that do some IO internally, but that are guaranteed to be side-effect free? Of course one would have to make sure that the array that is mutated inside getDistance must not be accessible from outside the function.<br>
<br>Is that possible? If not, wouldn't that be desirable? If not, why not?<br><br>Thanks<br><br> Daniel<br><br></div>