Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!ukma!husc6!spdcc!esegue!compilers-sender Newsgroups: comp.compilers Subject: Re: Enumerated data types. Keywords: Ada, design Message-ID: <13436.9008311312@lion.inmos.co.uk> Date: 31 Aug 90 13:12:00 GMT Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: Mike Harrison Organization: Compilers Central Lines: 51 Approved: compilers@esegue.segue.boston.ma.us dik t. winter (dik@cwi.nl) wrote: >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. > ... 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); type BIKE_COLOURS is (ORANGE, RED, GREEN, WHITE); and CAR_COLOURS'SUCC(RED) = BLUE BIKE_COLOURS'SUCC(RED) = GREEN 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. Mike. Michael P. Harrison - Software Group - Inmos Ltd. UK. UK : mph@inmos.co.uk, US : mph@inmos.com -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.