Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!sun-barr!apple!snorkelwacker!spdcc!ima!esegue!compilers-sender From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.compilers Subject: Re: Enumerated data types Keywords: C, Pascal, design, Ada Message-ID: <2007@charon.cwi.nl> Date: 24 Aug 90 22:48:54 GMT References: <1990Aug23.134826.2865@forwiss.uni-passau.de> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: dik@cwi.nl (Dik T. Winter) Organization: CWI, Amsterdam Lines: 49 Approved: compilers@esegue.segue.boston.ma.us (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 , and Mike Murphy .] -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.