On 10/05/2014, at 10:24 AM, gmhwxi wrote:
>
> In ATS, a pure function can write but it can only write
> to the memory it owns. The design in ATS goes like this:
>
> If I want to indicate to the compiler that that do_this and do_that
> can be evaluated in parallel, I use the following syntax:
>
> prval (pf1, pf2) = ... // [pf1] and [pf2] are separated
> val ... = do_this (pf1 | ...) // do_this is checked to be pure
> and ... = do_that (pf2 | ...) // do_that is checked to be pure
>
> Basically, the requirement is that (1) do_this and do_that can
> only manipulate resources they own and (2) they do not share
> any resources between them.
Ah yes of course, this is the standard ML notation.
I wonder, however, if you can also do this:
val (), () = f1 a1, f2 a2
[omitting proofs]
BTW: it isn't necessary that two procedures not modify shared
memory to use them in parallel. A simple example, they both
do atomic increments on a shared variable. Clearly the procedures
aren't pure, in fact no procedures can possibly be pure or they
would be worthless.
If you consider two processes modifying separate files,
clearly each has side effects, and it looks like these procedures
are independent. But this is NOT the case in the larger picture,
they're both modifying files in a single file system.
So the separation requirement is a fallacy: in its simple form
it is worthless. Clearly the real requirement is that some
invariant be satisfied "at some time in the future".
So actually I'd expect some form like:
prval (psync) = .. with
prval (pf1, pf2) =
..
where the psync is the synchronisation proof, and the individual proofs
pf1 and pf2 may take the synchronisation proof's conclusion as a premise.
[Or did I get this backwards .. lets see]
Roughly, if f1 and f2 each add 1 to a shared variable, then provided
addition is atomic, we can deduce that after both f1 and f2 have completed
the variable will be two greater.
But basically my point is: for functions purity or whatever may be useful
because the *system* manages the assignment of their result values
in some fixed specified way. Technically these are procedures with
side effects, and in general, procedures ALWAYS have side effects
because they don't return values and would be useless if they
didn't have side effects.
So functions are really procedures with system specified
side effects and a system invariant. Its a special case.