Pure functions in D

bearophile bearophileHUGS at lycos.com
Tue Sep 23 19:43:10 PDT 2008


Christopher Wright:
> > Will memory allocation be considered pure?
> 
> Allocating heap memory affects global state, to whit, the garbage 
> collector's state. I can't see how you can allow memory allocation.

The CPU isn't pure, asm changes states all the time. So even if you want to create the purest Haskell language, you have to perform impure operations at some level. This means that while your code can be pure as snow (except for I/O, done if you want using monads), the things that make it run can be impure. So it all becomes a matter of drawing a line, over that line your system/language is pure, under that line (with the microcode and transistors at the bottom) it's impure. So where's the D GC? Over or under the line? If it's considered under the line, them you may malloc memory keeping purity :-)

Bye,
bearophile



More information about the Digitalmars-d mailing list