[mercury-users] Translating from Prolog

Ralph Becket rafe at cs.mu.OZ.AU
Thu Jun 10 09:21:19 AEST 2004


hanberg at ruc.dk, Wednesday,  9 June 2004:
> Hi again
> 
> I haven't really made it work - what I would like to have translated is:
> 
> closes(X & Y) :- closes(X), closes(Y).
> closes(~~X) :- closes(X).

Your problem is that Mercury defines different precedences for the
`&' and `~' operators.  This can be overcome by inserting parentheses
to make it unambiguous:

closes(X & Y   ) :- closes(X), closes(Y).
closes(~(X ; _)) :- closes(X).
closes(~(_ ; Y)) :- closes(Y).
closes(~(~(X)) ) :- closes(X).

etc.

> I've tried doing this(and a lot more):
> 
> :- type &(X, Y) ---> X & Y.
> :- type ~(X) ---> ~X.
> 
> :- pred closes(_).
> 
> :- mode closes(in).
> 
> :- closes(X & Y) --> closes(X), closes(Y).
> :- closes(~~X) --> closes(X).

This isn't going to work because the patterns in the clause heads for
closes/1 now have different types - that's not allowed.

> But this doesn't seem to work - I must do someting simple wrong, but I
> have no idea what.

If you're primarily interested in getting things working, just take
care to put in the extra parentheses around `(_ & _)' and `~(_)'
terms and everything should work fine.

Let us know if you want more detail (I'd supply it right now, but I'm in
recovery after the ICFP contest...)

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