FW: RE: non destructive references

Zuurbier, E. - AMSXE Erik.Zuurbier@KLM.NL
Mon, 10 May 1999 17:57:26 +0200


> >(...) the function below is still not acceptable.
> >
> >readArray :: *{a} -> (*{a},a,a)
> >readArray arr = (arr,element1,element2)
> >where   element1 = select arr 3
> >        element2 = select arr 5
> >
> 
> The problem is NOT that the selection is non-desctructive. But, due to
> laziness, the selection is not performed BEFORE the resulting array is
> used
> destructively (which is possible since you deliver a unique result array).
> By forcing the evaluation of both selections, e.g. by writing
> 
> readArray arr
>       #! element1 = select arr 3
>          element2 = select arr 5
>       = (arr,element1,element2)
> 
> the function will be correct.
> 
Yes, I understand. But the real question is why the programmer should be
bothered with reformulating the where (or #)-construction to the
#!-construction. Why not have the compiler reason along lines such as the
following:

-First try to type the original program.
-Find out that this gives uniqueness problems, because of multiple
 references to arr.
-Then conclude that the program has to be transformed: evaluation of the
 selections has to be forced by replacing where (or #) by #!.
-Then try again to type the program.
-Success!
 
I understand that this can cause a lazy function with a non-unique argument
to become strict in that argument when the argument is made unique. But is
that a
problem? I have to do that manually anyway. The compiler could issue a
warning if it did a transformation like this.

Currently, I have to do *two* things: when I make an argument unique I
*also* have to make the function force evaluation to have the function
typed. Wouldn't it be a good idea to have the compiler figure out the
consequences for (#)-strictness when I make an argument unique?

Regards,
Erik Zuurbier