[m-dev.] Trouble with user-defined equality
Ralph Becket
rafe at cs.mu.OZ.AU
Fri Apr 16 14:11:49 AEST 2004
Ralph Becket, Thursday, 15 April 2004:
> I'm having trouble making a little non-canonical type example work.
> [...]
I've answered my own question: here's the trick of it in case anyone was
wondering:
:- module noncan.
:- interface.
:- type ch.
:- implementation.
:- import_module bool.
:- type ch ---> z ; s(ch) where equality is eq.
:- pred eq(ch::in, ch::in) is semidet.
eq(A, B) :- promise_only_solution(eq2(A, B)) = yes.
:- pred eq2(ch::in, ch::in, bool::out) is cc_multi.
eq2(z, z , yes).
eq2(z, s(_), no ).
eq2(s(_), z , no ).
eq2(s(X), s(Y), Eq ) :- eq2(X, Y, Eq).
Essentially, any switch on a non-canonical type must be guaranteed to
succeed, in which case it has mode cc_multi and therefore cannot appear
in context that can fail.
-- 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