[mercury-users] Hi, and determinism

Ralph Becket rbeck at microsoft.com
Wed Jan 31 20:06:53 AEDT 2001


>From Peter Schachte on 31/01/2001 08:49:56
> I would propose that your example predicate could instead be written:
> 
> 	correct(L,Ba,Bc) :-
> 		case L of
> 		    (	[] -> Ba = Bc
> 		    ;   [H|T] ->
> 			data_modify(H,Ba,Bb),
> 			correct(T,Bb,Bc)
> 		    ).
> 
> The case construct would be such that no matter the declared determinism
of
> the predicate it appears in, all the constructors of the type must be
> covered by exactly one case.  If not, it is a compile-time error, so if
the
> base case were omitted, an error would be reported.  Note also that this
> feature works no matter what mode correct is called in.  If it is somehow
> used to generate L, that's fine, and it'll still get a warning if a case
is
> missing or repeated.

How is this different from a normal switch?  Viz (using functional style),

	correct(L, Ba) = Bc :-
		( L = [],       Bc = Ba
		; L = [H | T],  Bc = correct(T, data_modify(H, Ba))
		).

The compiler will certainly spot any missing cases in a switch.

> It would probably be good to allow alternatives for the cases:
> 
> 	:- type foo ---> a(int) ; b(int) ; c ; d.
> 
> 	... case Foo of
> 		(   (a(X) ; b(X) ) -> some_really_long_body
> 		;   (c ; d) -> whatever
> 		)
> 
> Comments welcome, particularly from proponents of the approach of
splitting
> the predicate/function in two to take advantage of the determinism system.

I'd like it if switch detection could spot that the following was
exhaustive and exclusive:

	(	( Foo = a(X) ; Foo = b(X) ), ...case a/b...
	;	( Foo = c    ; Foo = d    ), ...case c/d...
	)

I've asked for this one before, but it was (then) a low priority goal.

Ralph

--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 

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