[mercury-users] Switches and Determinism

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


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.

Julien.

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