pure or not pure?

Russell Lewis webmaster at villagersonline.com
Thu Apr 10 08:49:29 PDT 2008


Janice Caron wrote:
>>  Not having the ability to pass around mutable heap data to and from pure
>>  functions is going to limit severely the usefulness of pure functions.
> 
> I don't see why. Functional programming languages such as Haskell seem
> not to mind. In many functional programming languages, there is no
> mutable data at all.

That's not quite true, and I think that the distinction is important. 
Haskell and the rest are constantly doing memory allocation, and that 
memory allocation has the potential to fail when you run out of memory. 
  It's simply that they hide it all behind their syntax.

Thus, I would argue that it is perfectly reasonable for a "pure" D 
function to allocate memory.  The question arises, then, what happens 
when you run out?  A pure function probably shouldn't be allowed to 
throw an exception (that would violate the pureness guarantees), so what 
do you do?  Or do you create a "PureFunctionFailedException" which is 
the only thing that a pure function might throw???



More information about the Digitalmars-d mailing list