"Christopher Wright" wrote > Simen Kjaeraas wrote: >> On Thu, 18 Dec 2008 07:01:49 +0100, Steven Schveighoffer >> <schvei...@yahoo.com> wrote: >> >>> Walter wants pure functions that have no side effects *AND* cannot be >>> affected by other functions' side effects. Your example fails the >>> second >>> requirement. >> >> I should have put that in there as well. My point was that a delegate >> /can be/ as pure as a normal function. > > Right, but the compiler might have to take it on faith that the delegate > is really pure.
It depends on the delegate. I'd say that a delegate that points to a closure, or stack frame, is inherently unpure. However, a delegate that points to a class instance member function can be pure if the class instance is immutable. The purity will be stored with the signature of the function (and therefore the type). So normal casts should work in the case that you know what you are doing, but there can't be any way for the compiler to know to cast the stack frame to immutable. What you could do is form a requirement that if any inner function of another function is marked as pure, then ALL inner functions must be marked as pure. Then, at the moment you pass a delegate to one of those functions, or call one of those functions, all local data becomes immutable. I don't see a lot of benefit to all that, but then again, I'm not really experienced with functional programming techniques. -Steve