Re: Enumerated data types

dik@cwi.nl (Dik T. Winter)
24 Aug 90 22:48:54 GMT

          From comp.compilers

Related articles
Enumerated data types mandel@forwiss.uni-passau.de (1990-08-23)
Re: Enumerated data types moss@cs.umass.edu (1990-08-24)
Re: Enumerated data types skrenta@amix.commodore.com (1990-08-15)
Re: Enumerated data types dik@cwi.nl (1990-08-24)
Re: Enumerated data types ok@goanna.cs.rmit.OZ.AU (1990-08-27)
Re: Enumerated data types jejones@microware.com (1990-08-27)
Re: Enumerated data types perelgut@turing.toronto.edu (1990-08-24)
Re: Enumerated data types dik@cwi.nl (1990-08-27)
Re: Enumerated data types grover@brahmand.Eng.Sun.COM (1990-08-28)
Re: Enumerated data types corbett@lupa.Eng.Sun.COM (1990-08-29)
[3 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: dik@cwi.nl (Dik T. Winter)
Keywords: C, Pascal, design, Ada
Organization: CWI, Amsterdam
References: <1990Aug23.134826.2865@forwiss.uni-passau.de>
Date: 24 Aug 90 22:48:54 GMT

(Couldn't mail because the mailer tells me host unknown.)


In article <1990Aug23.134826.2865@forwiss.uni-passau.de> mandel@forwiss.uni-passau.de (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. There are some contexts
where this is not possible:
colour_number: integer;
function num(a: car_colour) return integer ...;
function num(a: bike_colour) return integer ...;
now the statement:
colour_number := num(red);
is ambigous because it is valid for both possible explanations of red.
In this case (but also in non-ambiguous cases) the programmer has the
possibility to indicate what type red is meant:
colour_number := num(car_colour'(red));


Disambiguating this can be far from trivial, especially in complicated
expression. However, I have read that somebody has proven that when you
scan the expression first from the leaves to the root, next back again
to the leaves, back again to the root and still again to the leaves
would resolve all non-ambigous expressions (and ambiguous expressions are
illegal in Ada).


--
dik t. winter, cwi, amsterdam, nederland
dik@cwi.nl
[Similar comments on Ada arrived from Doug Hahn <hahn@tekcrl.labs.tek.com>,
and Mike Murphy <murphy@mips.COM>.]
--


Post a followup to this message

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