[mercury-users] Translating from Prolog

hanberg at ruc.dk hanberg at ruc.dk
Thu Jun 10 20:56:27 AEST 2004


Hi again

I hope it went well at the contest!

I'm still not on track, so if you would help me to a working example I will be
more than greatfull since I have used quite a bit of time that I don't really
have on it.

I'm trying this:

:- type &(A, B) ---> A & B.
:- type ~(A) ---> ~(A).

:- pred closes(_).
:- mode closes(in) is det.

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

But it is giving me these mistakes

test.m:032: Error: type `test:&/2' multiply defined.
test.m:023:   Here is the previous definition of type `test:&/2'.
test.m:038: Warning: clause in module interface.
test.m:039: Warning: clause in module interface.
test.m:040: Warning: clause in module interface.
test.m:041: Warning: clause in module interface.
test.m:044: Warning: clause in module interface.
test.m:038: In clause for predicate `test:closes/1':
test.m:038:   in argument 1 of clause head:
test.m:038:   type error in unification of variable `HeadVar__1'
test.m:038:   and functor `&/2'.
test.m:038:   variable `HeadVar__1' has type `V_1',
test.m:038:   functor `&/2' has type
test.m:038:   `(A & B) :: (test:(A & B))'.
test.m:039: In clause for predicate `test:closes/1':
test.m:039:   in argument 1 of clause head:
test.m:039:   type error in unification of variable `HeadVar__1'
test.m:039:   and functor `~/1'.
test.m:039:   variable `HeadVar__1' has type `V_1',
test.m:039:   functor `~/1' has overloaded type
test.m:039:   { (~ A) :: (test:(~ A)),
test.m:039:   (~ A) :: (test:'~'(A, V_2)) }.
test.m:039: In clause for predicate `test:closes/1':

I'm thinking it has something to do with the way I define the types but it seems
like I'm doing it the right way.

Tony



Quoting Ralph Becket <rafe at cs.mu.OZ.AU>:

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


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