[mercury-users] determinism of /

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jun 1 20:32:37 AEST 2001


On 01-Jun-2001, Stefan Karrmann <sk at mathematik.uni-ulm.de> wrote:
> Why is has division the mode det in the module int?

Because it can't succeed more than once, and can't fail.

> div(5,0) cannot succeed.
> 
> Okay, this is erroneous,

The determinism category `det' includes (is a superset of) the category
`erroneous'.

> but can't this be described more explicitly?

It would be possible to do so, but there would be little benefit in
doing so.

> Is it possible to define an instance, like this:
> 
> :- inst nonZero == bound (X), X /= 0.
> :- inst isZero == bound (X), X = 0.
> :- mode nonZero == nonZero >> nonZero.
> :- mode isZero == isZero >> isZero.
> 
> :- mode div (in, nonZero) = out is det.
> :- mode div (in, isZero) = out is failure.

Mercury doesn't support insts like `nonZero'.
You can define insts like `isZero', although the syntax is
different to what you have used above:

	:- inst isZero == bound (0).

Note that the determinism for the isZero mode of div
should be `erroneous', not `failure', since it can't fail.

So, div could be declared as

	:- mode div (in, in) = out is det.
	:- mode div (in, in(isZero)) = out is erroneous.

But as I said above I don't think there would be much benefit in
doing so.  Declaring multiple modes has some costs (we generate
separate code for each mode, and the current implementation is
not smart enough to share code between similar modes), and I
don't see any advantage in declaring it as above.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list