[mercury-users] Simple fact / deduction example, in mercury?

Ralph Becket rafe at cs.mu.OZ.AU
Tue Jul 9 16:01:14 AEST 2002


jdonner, Monday,  8 July 2002:
> Hi,
> 
>   I'm dabbling in prolog (& Haskell) and was attracted to
> mercury, but I'm finding documentation thin on simple facts
> / deductions.
> 
>   Can anyone give me a simple, fact / deduction example?
> Something as simple as a bunch of parent(a, b) facts,
> and an ancestor function, would be great.
> 
> Thanks for any help,

:- type person
	---> alice, alex, beth, bill,
	     cissy, carl, denise, dennis,
	     eva, ethan.

:- pred parent(person, person).
:- mode parent(in, out) is nondet.	% parent(A, B) -- A has parent B
:- mode parent(out, in) is nondet.	% parent(A, B) -- B is parent of A

parent(alice,  beth).
parent(alice,  bill).
parent(alex,   beth).
parent(alex,   bill).

parent(cissy,  denise).
parent(cissy,  dennis).
parent(carl,   denise).
parent(carl,   dennis).

parent(beth,   eva).
parent(bill,   eva).
parent(beth,   ethan).
parent(bill,   ethan).

parent(denise, eva).
parent(dennis, eva).
parent(denise, ethan).
parent(dennis, ethan).

:- pred ancestor(person, person).
:- mode ancestor(in, out) is nondet.	% ancestor(A, B) -- A has ancestor B
:- mode ancestor(out, in) is nondet.	% ancestor(A, B) -- B is ancestor of A

ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).

HTH,

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