Re: What is a type?
jacob navia <jacob@jacob.re mcomp.fr> writes:
[color=blue]
> Eric Sosman wrote:[color=green]
> >
> > One problem with this explanation is that it relies
> > on the idea of "a sequence of storage bits," which would
> > seem to imply that a type exists only in connection with
> > memory.[/color]
>
> Types are associated with objects, and objects must exist
> in memory somewhere.[/color]
An object, or a function, is treated as though it has a certain
representation type at any particular point in (execution) time.
But the memory exists independently of the representation type
that is used to access it at any particular point. Also values
can come into existence that prior to coming into existence
weren't stored in any object - consider
int a[10];
* (char *) &a[3] = 0;
The address value &a[3] springs into existence having an address
representation type, but very likely wasn't previously stored in any
object.
[color=blue][color=green]
> > However, values have types even if they're not
> > memory-resident. For example, in `x * 2' the `2' has
> > type `int' even if the compiler uses "add x,x" or maybe
> > "shl x,1" to calculate the value, thus expunging all traces
> > of "two-ness" from the code.
> >[/color]
>
> A compiler that does constant folding (the general case)
> doesn't destroy any types. It eliminates the objects (the
> constants) and with the objects, their types disappear too.
> I see no contradiction. The two in x*2 is eliminated and
> with it its type. But until is eliminated the type exists
> as a way of describing the bits in the machine representation
> of two.[/color]
Objects are run-time entities; they don't exist during the
compilation process. Instead, the compiler manipulates syntactic and
tree elements that correspond to objects (and functions!) that might,
or might not, exist at run-time. Perhaps a small distinction, but a
significant one. Precise language is important.
[color=blue]
> Note that types in this context are just descriptions of machine
> representations , as I said in my proposal.[/color]
There are program types and representation types, and it is
important to understand both. So, it is important to explain
both.
[color=blue][color=green]
> > To a beginner, a memory-centric explanation of "type"
> > may be helpful: it has a comforting solidity in what the
> > novice may perceive as a sea of abstraction. But I think
> > the approach has several drawbacks. It's inaccurate (as
> > shown above), it doesn't cover incomplete types (what's
> > the "sequence of storage bits" for a `void'?),[/color]
>
> void means "non", i.e. no type, and no corresponding object.
> int fn(void)
> means that fn has no objects declared as arguments.[/color]
The type 'void' is not "no type", but an incomplete [program] type
that can't be completed. It's right that there is no representation
type corresponding to program type 'void'; but, the type 'void' is
still a [program] type.
[color=blue][color=green]
> > The worst feature of the memory-centric approach may be
> > that it encourages people to think about the representations
> > of values rather than about the values themselves.[/color]
>
> Types are descriptions of memory objects. Note that all we can
> do in a machine is to abstract from a real number or from any
> real world object *some* characteristics and *represent* it
> in the machine.[/color]
Program types are (sometimes somewhat abstract) specifications for how
various syntactic entities can be combined. On a particular
implementation, they also specify a mapping to a corresponding
representation type (or perhaps several representation types).
jacob navia <jacob@jacob.re mcomp.fr> writes:
[color=blue]
> Eric Sosman wrote:[color=green]
> >
> > One problem with this explanation is that it relies
> > on the idea of "a sequence of storage bits," which would
> > seem to imply that a type exists only in connection with
> > memory.[/color]
>
> Types are associated with objects, and objects must exist
> in memory somewhere.[/color]
An object, or a function, is treated as though it has a certain
representation type at any particular point in (execution) time.
But the memory exists independently of the representation type
that is used to access it at any particular point. Also values
can come into existence that prior to coming into existence
weren't stored in any object - consider
int a[10];
* (char *) &a[3] = 0;
The address value &a[3] springs into existence having an address
representation type, but very likely wasn't previously stored in any
object.
[color=blue][color=green]
> > However, values have types even if they're not
> > memory-resident. For example, in `x * 2' the `2' has
> > type `int' even if the compiler uses "add x,x" or maybe
> > "shl x,1" to calculate the value, thus expunging all traces
> > of "two-ness" from the code.
> >[/color]
>
> A compiler that does constant folding (the general case)
> doesn't destroy any types. It eliminates the objects (the
> constants) and with the objects, their types disappear too.
> I see no contradiction. The two in x*2 is eliminated and
> with it its type. But until is eliminated the type exists
> as a way of describing the bits in the machine representation
> of two.[/color]
Objects are run-time entities; they don't exist during the
compilation process. Instead, the compiler manipulates syntactic and
tree elements that correspond to objects (and functions!) that might,
or might not, exist at run-time. Perhaps a small distinction, but a
significant one. Precise language is important.
[color=blue]
> Note that types in this context are just descriptions of machine
> representations , as I said in my proposal.[/color]
There are program types and representation types, and it is
important to understand both. So, it is important to explain
both.
[color=blue][color=green]
> > To a beginner, a memory-centric explanation of "type"
> > may be helpful: it has a comforting solidity in what the
> > novice may perceive as a sea of abstraction. But I think
> > the approach has several drawbacks. It's inaccurate (as
> > shown above), it doesn't cover incomplete types (what's
> > the "sequence of storage bits" for a `void'?),[/color]
>
> void means "non", i.e. no type, and no corresponding object.
> int fn(void)
> means that fn has no objects declared as arguments.[/color]
The type 'void' is not "no type", but an incomplete [program] type
that can't be completed. It's right that there is no representation
type corresponding to program type 'void'; but, the type 'void' is
still a [program] type.
[color=blue][color=green]
> > The worst feature of the memory-centric approach may be
> > that it encourages people to think about the representations
> > of values rather than about the values themselves.[/color]
>
> Types are descriptions of memory objects. Note that all we can
> do in a machine is to abstract from a real number or from any
> real world object *some* characteristics and *represent* it
> in the machine.[/color]
Program types are (sometimes somewhat abstract) specifications for how
various syntactic entities can be combined. On a particular
implementation, they also specify a mapping to a corresponding
representation type (or perhaps several representation types).
Comment