comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Extended Type Statements
Date: Tue, 17 Jan 2006 20:57:30 +0100
Date: 2006-01-17T20:57:25+01:00	[thread overview]
Message-ID: <q9limstwsglk.o38tj4yw7zc.dlg@40tude.net> (raw)
In-Reply-To: nkazf.13$Dk.10@newsread3.news.pas.earthlink.net

On Tue, 17 Jan 2006 18:04:03 GMT, Jeffrey R. Carter wrote:

> A type defines a set of values and a set of operations on those values. That's 
> the definition I learned, and is similar to the one in ARM 3.2. In Ada, some 
> type declaration statements define at type, while others don't. For example
> 
> type I is range 1 .. 10;
> 
> declares a set of values (1 .. 10) and a set of operations on those values ("+", 
> "-", and so on), while
> 
> type T is limited private;
> 
> declares no values and very few operations. Instead, it's the entire package 
> spec that T is in that defines the type:
> 
> package P_For_T is
>     type T is limited private;
> 
>     C : constant T;
> 
>     procedure Put (Into : in out T; Value : in Integer);
> 
>     function Get (From : T) return Integer;
> private -- P_For_T
>     ...
> end P_For_T;
> 
> I was wondering if it might be a good idea for a language (probably not Ada) to 
> have an extended type statement that covers both concepts with a single 
> statement. So an integer type could be declared as something like
> 
> type I is
> values =>
>     range 1 .. 10;
> end I;
> 
> and an ADT as
> 
> type T is
> values =>
>     C : constant;
> operations =>
>     limited => True;
> 
>     procedure Put (Into : in out T; Value : in Integer);
> 
>     function Get (From : T) return Integer;
> implementation =>
>     private;
> end T;
> 
> There could be sections in the statement for representation clauses and the like.
> 
> Any comments? Would this sort of thing have any value?

Some unsorted comments.

In ADT approach literals are undistinguishable constructing functions. So
there is no need to have any special constructs to denote them.

Further, types algebra (what actually Ada needs in a more elaborated from
than just record/array aggregation and tagged extension) offers many
opportunities. For example infinite literals like Universal_Integer and
Strings, can be easily incorporated through interface inheritance. You just
say that the type I implements a numeric interface and compiler will
routinely convert each Universal_Integer to your type by calling a
conversion function you define. This is close to your idea of T with Put
and Get. Just consider them as conversion functions *required* by the
compiler because T is declared as implementing the interface of
Universal_Integer.

Same with aggregates as constructing functions, there is no chance to
enumerate all possible array aggregates in a "type"-statement. What for?
Just let the user to define an aggregate-constructor. Done.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



      reply	other threads:[~2006-01-17 19:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-17 18:04 Extended Type Statements Jeffrey R. Carter
2006-01-17 19:57 ` Dmitry A. Kazakov [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox