Memory allocation purity

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu May 15 05:57:43 PDT 2014


On Thu, 15 May 2014 02:50:05 -0400, Ola Fosheim Grøstad  
<ola.fosheim.grostad+dlang at gmail.com> wrote:

> On Thursday, 15 May 2014 at 06:29:06 UTC, bearophile wrote:
>> A little example of D purity (this compiles):
>
>> bool randomBit() pure nothrow @safe {
>>     return (new int[1].ptr) > (new int[1].ptr);
>> }
>
> Yes, and then you may as well allow a random generator with private  
> globals. Because memoing is no longer sound anyway.

This has nothing to do with allocators being pure. They must be pure as a  
matter of practicality.

The issue that allows the above anomaly is using the address of something.  
There is a reason functional languages do not allow these types of things.  
But in functional languages, allocating is allowed.

To be honest, code that would exploit such an anomaly is only ever used in  
"proof" exercises, and never in real code. I don't think it's an issue.

-Steve


More information about the Digitalmars-d mailing list