How to fake pure
Timon Gehr
timon.gehr at gmx.ch
Tue Apr 8 15:54:52 UTC 2025
On 4/8/25 17:07, Guillaume Piolat wrote:
> On Tuesday, 8 April 2025 at 14:00:56 UTC, Jonathan M Davis wrote:
>> Of course, I'm also increasingly of the opinion that pure was a
>> mistake in general, because it does almost nothing in practice but
>> routinely doesn't work with straightforward code - and it's definitely
>> one of those attributes which gets in way when code needs to be
>> refactored
>
>
> And you really need pureMalloc to be applicable, hovewer it's a lie
> since the GC and malloc obviously have global state.
It's not really a lie. This is just a confusion of levels of
abstraction. Purely functional languages use memory allocators too, and
they can also run out of memory.
The underlying problem here is that `pure` in D does not have a formal
semantic meaning and there are some highly questionable choices such as
dependencies on memory addresses and FPU state being considered `pure`.
In any case, casting a memory allocator to `pure` should be fine. Any
reasonable definition of `pure` we can come up with in the future would
be compatible with that.
More information about the Digitalmars-d-learn
mailing list