Re: OO versus RDB

From: Dmitry A. Kazakov <mailbox_at_dmitry-kazakov.de>
Date: Fri, 7 Jul 2006 20:03:45 +0200
Message-ID: <cgx2djybkkj8$.1myfbw11ol8qo$.dlg_at_40tude.net>


On Fri, 07 Jul 2006 16:55:19 +0100, Adrian Hey wrote:

> Marshall wrote:

>> Heh. Funny you should mention that. It's also the case that
>> one can have a function that writes to global variables
>> but doesn't *read* from them, and it will *still* be
>> pure, in that the outputs depend only on the inputs.
>> 
>> The functional guys *really* hate it when I say *that*.

>
> Well maybe that's because you're wrong :-)
>
> Such a "function" isn't a function at all, and common program
> transformations and compiler optimisations (e.g. common sub-expression
> elimination) will modify/break programs in such cases.
>
> Basically, in order to be considered "pure" it is necessary but
> not sufficient that the result delivered by a function is dependent
> only on the values of it's arguments. It's also necessary that
> evaluation has no other observable effect. So a programs observable
> behavior is identical whether the same expression is evaluated just
> once or several times (or maybe not at all) and is also independent
> of evaluation order.

Yes. One could say that the effect of a pure subroutine is limited to its parameters and the result.

What is computed from what is irrelevant, that's a behaviour, which is only required to be invariant. [ One could imagine a pathological case where the argument might depend on the result: a pure function dispatching on the result which does not touch it, but does an in-out argument, for example, stores there the actual type of the result. (:-)) ]

I am not sure about composition (the evaluation time and order). Consider a "pure" subroutine called with an impure closure as the parameter. I would still call such thing pure. It is difficult to mix FP with imperative, but it is worth the efforts, IMO.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Received on Fri Jul 07 2006 - 20:03:45 CEST

Original text of this message