[mercury-users] (Newbie) translating this from Prolog?
Fergus Henderson
fjh at cs.mu.OZ.AU
Sun Mar 21 05:09:29 AEDT 2004
On 20-Mar-2004, Maurizio Colucci <seguso.forever at tin.it> wrote:
> I am studying mercury for evaluation in an AI program.
>
> Could you please help me translate this predicate from prolog?
>
> % List::input
> holds(List):-
> forall(member(M, List),
> call(M)).
Do the predicates in the list have side effects?
If not, this can be translated as
:- pred holds(list(pred)).
:- mode holds(in(list_skel(pred is semidet))) is semidet.
holds(List) :-
all [M] (member(M, List) => call(M)).
If they have side effects, but can't fail, then it could be translated to
:- pred holds(list(pred(io__state, io__state), io__state, io__state).
:- mode holds(in(list_skel(pred(di,uo) is det))) is det.
holds([]) --> [].
holds([M|Ms]) --> call(M), holds(Ms).
If the predicates in the list have side effects but can fail,
then you'd probably need to rewrite them so that they return a
value of type bool or maybe(T) rather than failing.
--
Fergus Henderson | "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