Fergus' hack (was Re: [mercury-users] polymorphism)
Fergus Henderson
fjh at cs.mu.oz.au
Wed Oct 1 21:17:43 AEST 1997
Bart Demoen wrote:
>
> :- type ab ---> (a ; b).
>
> :- inst a = bound(a).
> :- inst b = bound(b).
>
> :- pred f(ab,int,int).
> :- mode f(in(a),in,out).
> :- mode f(in(b),out,in).
>
> f(Z,X,Y) :-
> (Z = a ->
> Y is 1
> ; X is 7
> ).
...
> fergushack.m:032: In clause for `f(in(fergushack:a), in, out)':
> fergushack.m:032: mode mismatch in if-then-else.
> fergushack.m:032: `Y' :: unique(1), free.
The mode system is not sophisticated enough to figure out that
the condition of the if-then-else cannot fail in this mode.
The mode system keeps track of which goals cannot succeed,
but it does not analyse which goals cannot fail.
(The determinism system does that -- but determinism analysis
comes *after* mode analysis.)
If you write the code slightly differently, i.e.
f(Z,X,Y) :-
( Z = a, Y is 1
; Z = b, X is 7
).
then it will work fine.
--
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 128.250.37.3 | -- the last words of T. S. Garp.
More information about the users
mailing list