[mercury-users] hi & a feq queries

Thomas Charles CONWAY conway at cs.mu.OZ.AU
Tue Aug 18 11:09:22 AEST 1998


Donald Syme, you write:
> Thanks for your help.  Re. this last example: the point I was making
> was that the compiler has different behaviour on beta-equivalent forms,
> which surprised me, given Mercury is a pure language.  The "binding
> of the non-local variable" (a rather operational way to look at it)
> is clearly ok. in such limited cases.  But it's no big deal.

The binding of the non-local is a problem because at the time when
the closure is constructed, the compiler doesn't know if it will be:
	called zero times
	called excatly once
	called more than once

If it is called zero times, then the predicate contains a mode error,
because it does not satisfy its mode declaration (X would be free on
success, not ground as declared).

If it is called excatly once, all is well.

If it is (or may be) called more than once, there are problems, because
in the first call, the unification with X is an assignment, but in the
second and later calls, the unification with X is a test unification, so
if we were to allow this kind of program we would need to arrange for
different code to be called for the first and later calls.

> >	:- func f(int) = string.
> >	f(N) = (if N mod 2 = 0 then "foo\n" else "bar\n").
> 
> Ah.. stupid me.  However this form is not documented in the
> reference manual, but of course I should have just tried the most
> obvious thing!

Neither it is. We'll aim to address this in the next release.

Thomas
-- 
Thomas Conway <conway at cs.mu.oz.au>
Nail here [] for new monitor.  )O+



More information about the users mailing list