[mercury-users] Pred defns
fjh at cs.mu.OZ.AU
Sun Apr 5 07:10:42 AEST 1998
On 03-Apr-1998, Peter Schachte <pets at students.cs.mu.oz.au> wrote:
> On Fri, 3 Apr 1998, Fergus Henderson wrote:
> > > $stream = [....],
> > > parse($$stream, Value),
> > > $stream = . % make sure the whole input is consumed
> If you do write what I wrote above, and Mercury chooses the (in, out, out)
> mode, it is, in effect, choosing and implied mode when an exact mode also
> applies. Why would you ever want this?
Well, it might be more efficient that way.
(For example, if the test is likely to succeed most of the time --
as would be the case in this example, if the code you're parsing is
mostly syntactically correct, then it may be more efficient to do the test
once in the caller rather than potentially doing it multiple times
in the callee.)
The point here is just to keep the relationship between the code and its operational
semantics simple, so that programmers can easily exercise control over the
operational semantics if it should turn out to be necessary.
Making the mode system "smarter" doesn't necessarily help.
> And it'd be nice if, at least at more aggressive optimization
> levels, Mercury would reorder code in order to use the best modes.
Oh, I agree that it would be nice to do optimizations which achieved this sort of
effect at the more aggressive optimization levels. But it would be an optimization,
not part of the basic semantics.
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 220.127.116.11 | -- the last words of T. S. Garp.
More information about the users