Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #3211

Re: Languages with types like Ada

From gah4 <gah4@u.washington.edu>
Newsgroups comp.compilers
Subject Re: Languages with types like Ada
Date 2022-10-21 17:09 -0700
Organization Compilers Central
Message-ID <22-10-041@comp.compilers> (permalink)
References <22-10-034@comp.compilers>

Show all headers | View raw


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.

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Languages with types like Ada "Luke A. Guest" <laguest@archeia.com> - 2022-10-20 10:01 +0100
  Re: Languages with types like Ada antispam@math.uni.wroc.pl - 2022-10-21 12:30 +0000
    Re: Languages with types like Ada "Luke A. Guest" <laguest@archeia.com> - 2022-10-21 21:00 +0100
      Re: Languages with types like Ada Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-10-22 11:26 +0200
      Re: Languages with types like Ada Bo Persson <bo@bo-persson.se> - 2022-10-22 18:17 +0200
  Re: Languages with types like Ada gah4 <gah4@u.washington.edu> - 2022-10-21 17:09 -0700
  Re: Languages with types like Ada "Thomas F. Burdick" <thomas@burdick.fr> - 2022-10-22 14:30 +0200
    Re: Languages with types like Ada "Luke A. Guest" <laguest@archeia.com> - 2022-10-22 21:22 +0100
    Re: Languages with types like Ada Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-10-23 20:02 +0300
      Re: Languages with types like Ada "Luke A. Guest" <laguest@archeia.com> - 2022-10-23 20:17 +0100
    Re: Languages with types like Ada Andreas Rumpf <a.rumpf@crosssoft.de> - 2022-11-07 09:58 +0100

csiph-web