[mercury-users] Switch detection question

Ralph Becket rafe at cs.mu.OZ.AU
Wed May 22 10:39:36 AEST 2002


Ondrej Bojar, Tuesday, 21 May 2002:
> Hi.
> 
>   How can I write a code like this:
> 
> :- module clip.
> :- implementation.
> :- import_module int.
> 
> :- pred bar(int::in, int::out) is semidet.
> 
> bar(X, Y) :-
>   X = 5,
>     Y = 2;
>   (X = 3; X = 4),
>     Y = 7
>   .
> 
>   ...without confusing the switch detection algorithm?

bar(5, 2).
bar(3, 7).
bar(4, 7).

should do the trick.  We don't (yet) support multi-case switches (which
is what your code is trying to be.)

>   I prefer not to hear about if-then-else decistion tree or explicit
> enumeration of all the possible values:

The code I presented above is shorter than your example.  Unfortunately
there's no general way around the situation at present.

- 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