[mercury-users] ....use of solution/2
Ralph Becket
rafe at cs.mu.OZ.AU
Mon Mar 22 08:23:43 AEDT 2004
Stefan Hinterstoisser, Sunday, 21 March 2004:
>
> Thanx a lot for that... I`m just wondering if (because I looked it up
> and I`m not quite sure about it) I can give the solution/2 predicate
> also a predicate with several inputs (for sure only one output!)...
You can construct closures (or "partial applications") to do this.
For example,
Closure = find_route(Graph, Start, End),
Routes = solutions(Closure),
...
or equivalently just
Routes = solutions(find_route(Graph, Start, End)),
...
where you have find_route defined as
:- pred find_route(graph, vertex, vertex, list(vertex)).
:- mode find_route(in, in, in, out) is nondet.
> so would something like this work??
>
> pred predicat(out, in, in) is nondet. ...
^^^^ I think you mean `mode' here.
The signature for solutions/1 is
:- func solutions(pred(T)) = list(T).
:- mode solutions(pred(out) is multi) = out(non_empty_list) is det.
:- mode solutions(pred(out) is nondet) = out is det.
so you'd either have to use a lambda to get things right
Closure = ( pred(X::out) is nondet :- predicat(X, A, B) ),
Solutions = solutions(Closure),
...
or a "wrapper" predicate to do the same thing:
Solutions = solutions(reordered_predicat(A, B)),
...
where
:- pred reordered_predicat(..., ..., ...).
:- mode reordered_predicat(in, in, out).
reordered_predicat(A, B, X) :- predicate(X, A, B).
-- Ralph
--------------------------------------------------------------------------
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