From: Ole-Hjalmar Kristensen <ohk@maestro.clustra.com>
Subject: Re: Modular type. What is it and why?
Date: 1999/04/06
Date: 1999-04-06T00:00:00+00:00 [thread overview]
Message-ID: <umqr9pxwroy.fsf@maestro.clustra.com> (raw)
In-Reply-To: 7ede2p$pd1$1@its.hooked.net
"Mike Silva" <mjsilva@jps.net> writes:
> David C. Hoos, Sr. wrote in message <7eb2iq$jc3@hobbes.crc.com>...
> <....>
> >There are many uses for such a type -- e.g., the index of a circular array,
> or a representation of the days of the week...
>
> One of the little "goodies" I discovered in coming from C to Ada are modular
> types. I often had to write code like:
>
> switch ( key )
> {
> case ARROW_DOWN:
> if ( index < ( NUM_ELEMENTS - 1 ) )
> index++;
> else
> index = 0;
> break;
> case ARROW_UP:
> if ( index > 0 )
> index = NUM_ELEMENTS - 1;
> else
> index--;
> break;
> }
>
> Now with Ada I'll be able to write (assuming 'index' is the appropriate
> modular type):
>
> case ( key ) is
> when ARROW_DOWN =>
> index := index + 1;
> when ARROW_UP =>
> index := index - 1;
> end case;
>
> Now -that's- what I call progress!
>
> Mike
>
>
>
>
Yes, this is a good illustration of modular types. However, what do
you do if NUM_ELEMENTS change?
Maybe modular types isn't the right choice in this case.
--
E pluribus Unix
prev parent reply other threads:[~1999-04-06 0:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-05 0:00 Modular type. What is it and why? Staffan Dittmer
1999-04-05 0:00 ` Marin David Condic
1999-04-05 0:00 ` David C. Hoos, Sr.
1999-04-06 0:00 ` Mike Silva
1999-04-06 0:00 ` Mike Silva
1999-04-07 0:00 ` Robert Dewar
1999-04-07 0:00 ` Bret
1999-04-11 0:00 ` Florian Weimer
1999-04-06 0:00 ` Marin David Condic
1999-04-06 0:00 ` Mike Silva
1999-04-06 0:00 ` bglbv
1999-04-07 0:00 ` Ole-Hjalmar Kristensen
1999-04-07 0:00 ` Mike Silva
1999-04-07 0:00 ` Stephen Leake
1999-04-08 0:00 ` Ole-Hjalmar Kristensen
1999-04-06 0:00 ` Ole-Hjalmar Kristensen [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox