[mercury-users] Hi, and determinism
Peter Schachte
schachte at cs.mu.OZ.AU
Fri Feb 2 11:32:00 AEDT 2001
On Wed, Jan 31, 2001 at 01:06:53AM -0800, Ralph Becket wrote:
> 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.
Not if you declare correct/2 to be semidet. Or nondet (if it were a
predicate).
The difference is that the case construct would always be required to be
exclusive and exhaustive for the constructors of the type, regardless of the
determinism of the predicate or function it appears in or of the determinism
of the predicates or functions invoked in the bodies of the cases. This
removes the necessity of forcing a predicate to be deterministic, whether or
not that's appropriate, just to get error messages for missing or repeated
cases.
--
Peter Schachte <schachte at cs.mu.OZ.AU> One thing's for sure: if we keep
http://www.cs.mu.oz.au/~schachte/ doing what we're doing, we're going
Phone: +61 3 8344 9166 to keep getting what we're getting.
Fax: +61 3 9348 1184 -- Stephen Covey, et al.
--------------------------------------------------------------------------
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