Re: Enumerated data types.

Mike Harrison <!!mph>
Fri, 31 Aug 90 14:12:00 BST

          From comp.compilers

Related articles
Re: Enumerated data types.!!mph (Mike Harrison) (1990-08-31)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Mike Harrison <!!mph>
Keywords: Ada, design
Organization: Compilers Central
Date: Fri, 31 Aug 90 14:12:00 BST

dik t. winter ( wrote:
>In article <> (Luis Mandel) writes:
>> Now my question is: anybody knows if there are languages that allows
>> anything like
>> car_colours = (red, blue, brown, black);
>> bike_colours = (orange, red, green, white);
>Yes, Ada.
>> and have these functions defined with an extra parameter, for example:
>> suc (car_colour, red) = blue
>> suc (bike_colour, red) = green
>No extra parameter is required in Ada. The reason is that overload
>resolution (the two functions suc overload each other) is not only done
>on the type of parameter but also on the required type of the result.
>I.e. in:
> ford_colour := suc(red)
>it is known that ford_colour is of type car_colour and so it is known
>that suc is the function on type car_colour.
> ...

This is not true, because 'suc' is neither a function nor an operator in Ada,
it is an attribute.

Thus (translating Luis Mandel's example into Ada) we have:

        type CAR_COLOURS is (RED, BLUE, BROWN, BLACK);



This shows that the SUCC attribute (whose value is a function) must be
qualified by the type (or subtype) of value to which it is to be applied.

Dik's other comments about the resolution of expressions containing
enumeration values are quite correct.


Michael P. Harrison - Software Group - Inmos Ltd. UK.
UK :, US :

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.