[mercury-users] Switches with an "else" branch?

Ondrej Bojar oboj7042 at ss1000.ms.mff.cuni.cz
Sat Nov 10 02:41:10 AEDT 2001


Hi.

I'm trying to write deterministic switches but cover many cases in one
branch:

:- type my_type ---> one; two; three; four.

:- pred my_pred(my_type::in) is det.

my_pred(one).
my_pred(two).
my_pred(Else) :-
  Else \= one, Else \= two.

The Mercury compiler doesn't infer that all cases are covered (exactly
once) and claims:

testdetswitch.m:008: In `my_pred(in)':
testdetswitch.m:008:   error: determinism declaration not satisfied.
testdetswitch.m:008:   Declared `det', inferred `semidet'.
testdetswitch.m:010:   The switch on HeadVar__1 does not cover
                        testdetswitch:four/0 and/or testdetswitch:three/0.
testdetswitch.m:013:   Negated goal can succeed.
testdetswitch.m:013:   Negated goal can succeed.
testdetswitch.m:010:   Disjunction has multiple clauses with solutions.

Is nested if-then-else the only way to write such "switches with default"?

Thanks, Andrew.

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