forcing weak purity

Steven Schveighoffer schveiguy at yahoo.com
Wed May 23 06:57:19 PDT 2012


On Wed, 23 May 2012 09:52:31 -0400, deadalnix <deadalnix at 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


More information about the Digitalmars-d mailing list