Yes. Use the ST ("State Thread") monad. Data.Array.ST, STRef etc.2009/4/22 Daniel K. <[email protected]>: > Hello, > > 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 > > getDistance :: Graph -> Node -> Node -> IO Int > > 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! > 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. > > Is that possible? If not, wouldn't that be desirable? If not, why not? > > Thanks > > Daniel > > > _______________________________________________ > Haskell-Cafe mailing list > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe > > -- Eugene Kirpichov Web IR developer, market.yandex.ru _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
