[m-dev.] Trouble with user-defined equality

Ralph Becket rafe at cs.mu.OZ.AU
Thu Apr 15 15:01:23 AEST 2004


I'm having trouble making a little non-canonical type example work.

Consider the following:

:- module noncan.
:- interface.

:- type ch.

:- implementation.

:- type ch ---> z ; s(ch) where equality is eq.

:- pred eq(ch::in, ch::in) is semidet.

eq(z,    z   ).
eq(s(X), s(Y)) :-
    X = Y.

The compiler complains that

noncan.m:012: In switch on variable `HeadVar__1':
noncan.m:012:   error: unification for non-canonical type
noncan.m:012:   `noncan.ch/0'
noncan.m:012:   occurs in a context which requires all solutions.
noncan.m:013:   In argument 1 of clause head:
noncan.m:013:   error: unification for non-canonical type
noncan.m:013:   `noncan.ch/0'
noncan.m:013:   occurs in a context which requires all solutions.
noncan.m:013:   In argument 2 of clause head:
noncan.m:013:   error: unification for non-canonical type
noncan.m:013:   `noncan.ch/0'
noncan.m:013:   is not guaranteed to succeed.
noncan.m:012:   In argument 2 of clause head:
noncan.m:012:   error: unification for non-canonical type
noncan.m:012:   `noncan.ch/0'
noncan.m:012:   is not guaranteed to succeed.

Trying to tackle the "is not guaranteed to succeed" complaints, I change
the definition of `eq/2' to

eq(z,    z   ).
eq(z,    s(_)) :- false.
eq(s(_), z   ) :- false.
eq(s(X), s(Y)) :- X = Y.

and get

noncan.m:012: In switch on variable `HeadVar__1':
noncan.m:012:   error: unification for non-canonical type
noncan.m:012:   `noncan.ch/0'
noncan.m:012:   occurs in a context which requires all solutions.
noncan.m:014:   In argument 1 of clause head:
noncan.m:014:   error: unification for non-canonical type
noncan.m:014:   `noncan.ch/0'
noncan.m:014:   occurs in a context which requires all solutions.
noncan.m:012: In switch on variable `HeadVar__2':
noncan.m:012:   error: unification for non-canonical type
noncan.m:012:   `noncan.ch/0'
noncan.m:012:   occurs in a context which requires all solutions.
noncan.m:015:   In argument 2 of clause head:
noncan.m:015:   error: unification for non-canonical type
noncan.m:015:   `noncan.ch/0'
noncan.m:015:   occurs in a context which requires all solutions.
noncan.m:012: In switch on variable `HeadVar__2':
noncan.m:012:   error: unification for non-canonical type
noncan.m:012:   `noncan.ch/0'
noncan.m:012:   occurs in a context which requires all solutions.

I've tried all sorts of other approaches without success.  Can someone
show me what I'm doing wrong?

-- Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list