[mercury-users] hi & a feq queries
Thomas Charles CONWAY
conway at cs.mu.OZ.AU
Tue Aug 18 11:01:28 AEST 1998
Peter Schachte, you write:
> I thought the compiler now did switch detection on if-then-elses, too? In
> any case, as you say, the functional match form is much more akin to an
> if-then-else, so I think this is the right way to translate it. If the
> cases overlap, as they do here, it could get pretty painful to force them
> not to overlap in the generated Mercury code, in order to get it to be det.
> Especially when there's no need to do that with an if-then-else.
We know how to implement switch detection on if-then-elses, but it will
be a moderate amount of work, which noone has found time for, yet.
There is another reason apart from efficiency that a switch should be
preferred - once you've gone to the trouble (and it is rarely much
trouble) of making all the cases (except the default) mutually
exclusive, a switch is more likely to be more maintainable, simply
because the compiler will detect it if your modifications lead to
cases that are not mutually exclusive. There have been numerous
cases in the compiler where we originally used if-then-elses, but
changed to using switches when we discovered that we'd missed
cases.
Thomas
--
Thomas Conway <conway at cs.mu.oz.au>
Nail here [] for new monitor. )O+
More information about the users
mailing list