[mercury-users] Switches and Determinism

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Sep 11 14:16:20 AEST 2006


On Mon, 11 Sep 2006, Julien Fischer wrote:

>
> On Mon, 11 Sep 2006, Jonathan Morgan wrote:
>
>> If I have a type like the following type:
>> 
>> :- type switch_test --->
>> 	type1;
>> 	type2;
>> 	type3.
>> 
>> Then the following code looks fairly deterministic to me.
>> 
>> :- func test(switch_test) = int.
>> test(S) = Y :-
>> 	(
>> 		S = type1,
>> 		Y = 1
>> 	;
>> 		(S = type2
>> 		; S = type3),
>> 		Y = 2
>> 	).
>> 
>> However, the compiler tells me that this is non-deterministic.  Surely
>> things like this are wanted in other places?  How can you make it so
>> that a switch has one clause for multiple types being switched on?
>> 
>> switch_test.m:015: In `test(in) = out':
>> switch_test.m:015:   error: determinism declaration not satisfied.
>> switch_test.m:015:   Declared `det', inferred `nondet'.
>> switch_test.m:018:   Unification of `S' and `switch_test.type1' can fail.
>> switch_test.m:022: The switch on S does not cover switch_test.type1/0.
>> switch_test.m:018:   Disjunction has multiple clauses with solutions.
>> switch_test.m:015: Error: invalid determinism for `test(in) = out':
>> switch_test.m:015:   the primary mode of a function cannot be `nondet'.
>> For more information, try recompiling with `-E'.
>
> What version of the compiler are you using?  The above code compiles
> without complaint for me using the 0.13 beta or rotd.
>

In answer to my own question: you're using 0.12.X.

>From the NEWS file for 0.13:

* We now have support for recognizing switches in which multiple switch arms
   have shared code. Where previously programmers had to write code like this

   (
   	X = a,
 	... code for a ...
   ;
   	X = b(...),
 	... code for b ...
   ;
   	X = c,
 	... code for c ...
 	... shared code ...
   ;
   	X = d(...),
 	... code for d ...
 	... shared code ...
   )

   to have the disjunction recognized as a switch on X, they can now write
   code like this:

   (
   	X = a,
 	... code for a ...
   ;
   	X = b(...),
 	... code for b ...
   ;
   	(
 		X = c,
 		... code for c ...
 	;
 		X = d(...),
 		... code for d ...
 	),
 	... shared code ...
   )
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list