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.

Referentially transparent mutability can also be achieved on the  
Clojure side by using a monad to secure the access to the array.

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.

The security mechanism in the Haskell implementation is provided by  
the type system. For Clojure, something else needs to be done.  
Perhaps declaring most definitions private will do the trick, but I  
haven't thought this through in detail.

The net result is that there would be a way to create a new array and  
immediately modify it using monadic operations. The final array could  
be taken out of the monad, but is then immutable because there is no  
way to get it inside a monad again.

Konrad.


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to