[mercury-users] Re: Fergus' hack

Fergus Henderson fjh at cs.mu.oz.au
Fri Oct 3 18:25:34 AEST 1997


Bart Demoen wrote:
> 
> It is very reasonable to want to implement two different modes
> of the same predicate with a different algorithm [...] - but the reality is
> that Mercury doesn't offer support to do that.

Actually it _is_ possible to do that sort of thing in Mercury...
but if you thought the code I posted last time was a hack,
well, suffice it to say that you probably wouldn't like it ;-)

> What I would like to specify - declare if you want - is (a simple example)
> 
> 	:- mode p(in,out) is det with_clauses [p(X,Y) :- somealgo ].
> 	:- mode p(out,in) is det with_clauses [p(X,Y) :- someotheralgo ].

> Now, this looks perhaps bad, because there is no guarantee
> that somealgo and someotheralgo define the same relation between X and
> Y, so that by reordering a call to p/2, the meaning of the program
> might change.

Right.  That's why Mercury doesn't offer any direct support for this
sort of thing.  It is a feature which is easy to misuse.

> But adding the extra forward/backward argument to p
> gives the impression that the same relation exists between X and Y in
> both modes,

Huh?  Why do you think that?

> while this is also not necessarily the case (and in
> Fergus' example it wasn't, was it ?).

No.

> declarative programming with modes  [...]
> should be done in an environment that supports declarations (+
> proofs, supplied by users, or derived by the compiler) about the
> equivalence of e.g. p1 and p2, or somealgo and someotheralgo. That's
> something a declarative language should support and encourage,
> not tricky use of modes.

Agreed.

An environment with support for those kind of declarations with
user-provided proofs and compiler proof-checking would be ideal.
Currently Mercury doesn't provide such an environment.

On the other hand, I'm not aware of any programming language that does.

-- 
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