[m-dev.] Adding default clauses to the language.

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Aug 9 14:46:18 AEST 2001


On 09-Aug-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> But I guess what attracts me to this idea is that I find it very natural to
> think in terms of a catch-all case, like a default label in a C switch.  I
> find the status quo of requiring me to write two predicates/functions, or a
> huge if-then-else more unpleasant than allowing otherwise clauses.

A year or two ago, we discussed another language extension that would solve
this problem, at least in contexts where you want to switch on finite types,
without introducing constructs such as "otherwise". The change is simply to
require switch detection to look inside disjunctions in disjuncts, so that
predicates such as

:- type t ---> a; b; c; d; e.

:- pred p(t::in, int::out) is det.

p(a, 1).
p(b, 2).
p(c, 3).
p(X, 4) :-
	( X = d
	; X = e
	).

can be proven to be deterministic.

The reason why we haven't implemented it is that implementing it requires
generalizing the HLDS switch construct (associating a list of function symbols,
not just one, with each case), and that requires changes in almost every part
of the compiler. Mostly easy changes, but still a lot of work.

Zoltan.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list