comp.lang.ada
 help / color / mirror / Atom feed
* Extended Type Statements
@ 2006-01-17 18:04 Jeffrey R. Carter
  2006-01-17 19:57 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 2+ messages in thread
From: Jeffrey R. Carter @ 2006-01-17 18:04 UTC (permalink / raw)


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?

-- 
Jeff Carter
"I'm a kike, a yid, a heebie, a hook nose! I'm Kosher,
Mum! I'm a Red Sea pedestrian, and proud of it!"
Monty Python's Life of Brian
77



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Extended Type Statements
  2006-01-17 18:04 Extended Type Statements Jeffrey R. Carter
@ 2006-01-17 19:57 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry A. Kazakov @ 2006-01-17 19:57 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-01-17 19:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-17 18:04 Extended Type Statements Jeffrey R. Carter
2006-01-17 19:57 ` Dmitry A. Kazakov

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