Re: Languages with types like Ada

gah4 <gah4@u.washington.edu>
Fri, 21 Oct 2022 17:09:57 -0700 (PDT)

          From comp.compilers

Related articles
Languages with types like Ada laguest@archeia.com (Luke A. Guest) (2022-10-20)
Re: Languages with types like Ada antispam@math.uni.wroc.pl (2022-10-21)
Re: Languages with types like Ada laguest@archeia.com (Luke A. Guest) (2022-10-21)
Re: Languages with types like Ada gah4@u.washington.edu (gah4) (2022-10-21)
Re: Languages with types like Ada DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2022-10-22)
Re: Languages with types like Ada thomas@burdick.fr (Thomas F. Burdick) (2022-10-22)
Re: Languages with types like Ada bo@bo-persson.se (Bo Persson) (2022-10-22)
Re: Languages with types like Ada laguest@archeia.com (Luke A. Guest) (2022-10-22)
Re: Languages with types like Ada christopher.f.clark@compiler-resources.com (Christopher F Clark) (2022-10-23)
Re: Languages with types like Ada laguest@archeia.com (Luke A. Guest) (2022-10-23)
[1 later articles]
| List of all articles for this month |
From: gah4 <gah4@u.washington.edu>
Newsgroups: comp.compilers
Date: Fri, 21 Oct 2022 17:09:57 -0700 (PDT)
Organization: Compilers Central
References: 22-10-034
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="78742"; mail-complaints-to="abuse@iecc.com"
Keywords: types
Posted-Date: 21 Oct 2022 20:21:09 EDT
In-Reply-To: 22-10-034

On Thursday, October 20, 2022 at 2:08:50 PM UTC-7, Luke A. Guest wrote:


> I've been using Ada for a while and I cannot seem to find any other
> languages which were developed which had a similar/same way of embedding
> information into types (including basic discrete types). Are there any?


It seems that Ada has range types, like Pascal.


It also has something similar to enumeration types that some other languages
now have, at least back to C.


There is a more general question about how to generalize types in a language.


Fortran I has INTEGER and REAL, which have whatever representation the
underlying hardware has. There is no choice.


PL/I, not so many years later, allowed the generalization that one could
specify the number of bits or decimal digits one wanted.


PL/I has attributes instead of types, where one selects the appropriate ones.


There is FIXED or FLOAT, then BINARY or DECIMAL, and REAL or COMPLEX,
and finally precision, and for FIXED types, scale.


You declare FLOAT DEC(10) if you need at least 10 decimal digits.
(The underlying hardware might be binary, but with the appropriate bits.)


This can be slightly inconvenient, as in a type sense (and I think this is what
you are asking), anything with different attributes is a different type.


You can't call a subroutine with FLOAT DEC(10) if it expects FLOAT DEC(16),
even when you know that the underlying representation is the same.


When Fortran finally got the KIND system years later, it works differently.


You can ask for SELECTED_REAL_KIND(10), which gives you an integer.
You then use that when declaring the variables, as a KIND value.


Two variables with the same KIND are the same, even if you ask for
them with different SELECTED_REAL_KIND() arguments.


There are also functions that let you determine, for example, the
precision or radix or exponent range of a specific KIND.


There is no right answer to variable types. All choices make some
things easier, and other things harder.


Post a followup to this message

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