[mercury-users] Higher-order predicates
Douglas Michael Auclair
dauclair at hotmail.com
Fri May 31 00:06:11 AEST 2002
Hi,
I have some predicates, one of which is defined thus:
:- pred foo(bar, bar).
:- mode foo(in, in) is semidet.
:- mode foo(in, out) is nondet.
:- mode foo(out, in) is nondet.
foo(X, Z) :- quux(X, Y), quux(Y, Z), X \= Z.
The problem is that in my main, I cannot use foo as a higher-order predicate
(for solutions); the compiler complains that this is not an implemented
feature ("Taking the address of a pred with multiple modes") and suggests
making a lambda expression. But:
main -->
{ Foof = pred(X::in, Z::out) is nondet :- foo(X, Z),
solutions(Foof(baz), Bars) },
% using Bars
.
doesn't work either. The compiler states that (Foof) has type
pred((parents:bar), (parents:bar)) and that it was expecting type ((func
V_3) = V_4). When I make a function instead:
{ Fn = (func(X) = Z is nondet :- foo(X, Z)),
solutions(Fn(baz), Bars) }, % ...
the compiler complains it was looking for type (pred T). Back to square
one.
I solved the problems with a new top-level predicate:
:- pred foo_helper(bar, bar).
:- mode foo_helper(in, out) is nondet.
foo_helper(X, Z) :- foo(X, Z).
but this solution is distasteful (it pollutes the namespace, for one, making
the code less elegant/maintainable/comprehensible, especially when there's N
mult-moded predicates I must process through solutions/2).
What is the way to create a higher-order predicate that's visible only in
the local context?
Sincerely,
Doug Auclair
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
--------------------------------------------------------------------------
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