On 23-05-2012 16:03, deadalnix wrote:
Le 23/05/2012 15:57, Steven Schveighoffer a écrit :
On Wed, 23 May 2012 09:52:31 -0400, deadalnix <deadal...@gmail.com>
wrote:

Le 23/05/2012 14:35, Steven Schveighoffer a écrit :
Yes. Memory allocation and deallocation from a global heap is by
definition an impure operation (it affects global state). However, we
must make exceptions because without being able to allocate memory,
pure
functions become quite trivial and useless.

In functional languages, if such exceptions were not granted, a program
would not be able to do much of anything.


Yes, you are missing the point.

collect is not something you should be able to call in a pure
function. It can be triggered by allocating, but at this point you
already are in an impure context called from a pure context.

At the end, you need an unsafe way to call impure code in pure
functions.

I'm failing to see an argument in this response. If I can call an impure
function for allocating memory, why is it illegal to call an impure
function for collecting unused memory?

-Steve

Allocating is a much more simpler operation than collect, and its impact
is way more reduced.

Yes, but allocation implies possible collection!


Plus, allocating memory is something mandatory to do anything non
trivial. GC collect isn't that important, as it can be triggered by
allocating mecanism itself (and this mecanism is already impure).

If you do allow everything impure to be done on pure function based on
the fact that allocating is impure, what is the point to have pure
function at all ?

The point is *real world practicality*. You need to be able to use the core.memory API in pure functions to do anything memory-heavy.

--
Alex Rønne Petersen
a...@lycus.org
http://lycus.org

Reply via email to