forcing weak purity
Steven Schveighoffer
schveiguy at yahoo.com
Wed May 23 07:19:29 PDT 2012
On Wed, 23 May 2012 10:03:01 -0400, deadalnix <deadalnix at gmail.com> wrote:
> Le 23/05/2012 15:57, Steven Schveighoffer a écrit :
>> 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
>
> Allocating is a much more simpler operation than collect, and its impact
> is way more reduced.
Huh? Allocation *does* a collect! How can it be "simpler"?
> 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 ?
Memory collection is hardly "everything." We are looking at the few
exceptions needed to make the system usable.
-Steve
More information about the Digitalmars-d
mailing list