pure or not pure?

Steven Schveighoffer schveiguy at yahoo.com
Thu Apr 10 07:42:26 PDT 2008


"Janice Caron" wrote
> On 10/04/2008, Steven Schveighoffer wrote:
>>  Or do I have to re-implement it in every pure
>>  function I use?
>
> You can make a pure function to return an immutable array, and then
> duplicate it within f and g.

So your solution is, create a duplicate array that is never used again, 
thereby increasing the runtime (and memory allocation) of the pure function, 
and lowering the performance of the application.  I can't wait to use 
functional programming, it sounds awesome :)

>>  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.

Of course functional programming languages have mutable data.  They just 
don't have SHARED data.  We need immutable data in D because D is not a 
functional language and can share data, so that data needs to be immutable. 
But data that isn't shared shouldn't need to be immutable.

So let me restate: not having the ability to pass around UNIQUE mutable heap 
data to and from pure functions is going to limit severely the usefulness of 
pure functions.

-Steve 





More information about the Digitalmars-d mailing list