[m-dev.] ground >> dead

Mark Brown mark at csse.unimelb.edu.au
Mon Jan 15 23:27:13 AEDT 2007


On 15-Jan-2007, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
> 
> On Mon, 15 Jan 2007, Mark Brown wrote:
> >	main(!IO) :-
> >		p("foo", X),
> >		write_string(X, !IO),
> >		nl(!IO).
> >
> >	:- pred p(string::ground >> dead, string::out) is det.
> >
> >	p(X, X).
> >
> >It's hard to see that this mode is useful, however, since it imposes a
> >restriction on the caller for which there is no corresponding gain (that
> >I can see).
> 
> I think that it was an attempt to disallow further forward references to the
> argument (it makes more sense if you change the argument in your example
> to a variable).

Yes.  If the body of main is changed to

        W = "foo",
        p(W, X),
        write_string(X, !IO),
        write_string(W, !IO),
        nl(!IO)

then the following is reported:

t.m:012: In clause for `main(di, uo)':
t.m:012:   in argument 1 of call to predicate `t.p'/2:
t.m:012:   unique-mode error: the called procedure would clobber its argument,
t.m:012:   but variable `W' is still live.

even though

        W = "foo",
        V = W,
        p(W, X),
        write_string(X, !IO),
        write_string(V, !IO),
        nl(!IO)

(which is operationally equivalent, but avoids the forward reference) is
accepted.

> At the very least the compiler should give you a warning with modes like
> this.

On closer reading of the reference manual, I think it should be an error.
Dead is defined as "there are no references to the corresponding value", but
this isn't true for p unless the first argument initially contains the last
(i.e., unique) reference to the corresponding value.

Cheers,
Mark.

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list