[mercury-users] Preferred coding style for switches

Peter Ross petdr at cs.mu.OZ.AU
Fri Dec 10 14:31:11 AEDT 1999


On 09-Dec-1999, Ralph Becket <rbeck at microsoft.com> wrote:
> 
> > If some bar's are not needed for the foo's, another avantage 
> > of switches
> > could be that it could be rewritten as if-then-else and like 
> > this, it could
> > be easy to program a "default" case for the bar's not used, 
> > and maybe make
> > this deterministic. I think the determinism analysis of 
> > Mercury is more
> > safe when programming with switchs.
> 
> In Mercury parlance, a switch is an exhaustive test against the possible
> type constructors a variable can have.  This might be implemented as
> cascading if-then-elses or as a lookup table [Mercury chaps: what rule
> does get used?]  

I believe the options `--dense-switch-req-density',
` --lookup-switch-req-density' and so on decide whether or not a switch
is output or a sequence of if-then-elses.

Unfortunately our switch detection and generation code is spread through
multiple modules.  Zoltan would like someone to go in and factor all the
common parts out so that all the different types of switches are
handled in one spot.  It would make a nice starting project for anyone
wanting to learn about the Mercury project.  Volunteers?

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