On Sun, May 17, 2009 at 1:15 PM, Konrad Hinsen <konrad.hin...@laposte.net>wrote:
> > On 16.05.2009, at 15:53, aperotte wrote: > > > Yes Anand, I'm worried about that. What I think the solution should > > be is to allow mutability in the implementation of algorithms in the > > java back end for the reasons you mentioned, but a clean immutable > > interface on the clojure side. When users are faced with serious > > memory limitations, though, that could be a problem. The question is > > whether that sacrifice is worth the cleanliness of immutability. > > A detailed explanation is given in Philip Wadler's paper "Monads for > functional programming" (downloadable from http:// > homepages.inf.ed.ac.uk/wadler/topics/monads.html). The principle is > to have a specialized version of the state monad in which the state > is the array. The only way to get an array into the state is by > creating a new one immediately as a state monad value (meaning there > is no way to access the array otherwise). It can then be modified > using a set of monadic expressions that can be combined arbitrarily. > They guarantee that updates happen in the specified order without > permitting any other access to the array, meaning that the updates > can be made destructively without causing any problems. > Huh, sounds like just the thing. Security is going to be especially difficult in Clojure, though. For example, say I stuck the array into a ref from within the monad, then carried on overwriting it. A consumer who gets the array out of the ref from another thread might get it while I'm still mutating it. Granted that would be a pretty stupid thing for me to do, but it would be nice to guarantee immutability to consumers. Anand --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---