What is Expressiveness in a Computer Language

Chris Smith cdsmith at twu.net
Mon Jun 26 15:02:33 EDT 2006


George Neuner <gneuner2/@comcast.net> wrote:
> On Sun, 25 Jun 2006 14:28:22 -0600, Chris Smith <cdsmith at twu.net>
> wrote:
> 
> >George Neuner <gneuner2/@comcast.net> wrote:
> >> >Undecidability can always be avoided by adding annotations, but of 
> >> >course that would be gross overkill in the case of index type widening.
> >> 
> >> Just what sort of type annotation will convince a compiler that a
> >> narrowing conversion which could produce an illegal value will, in
> >> fact, never produce an illegal value?
> >
> >The annotation doesn't make the narrowing conversion safe; it prevents 
> >the narrowing conversion from happening. 
> 
> That was my point ... you get a program that won't compile.

That's not actually the case here.  If we're talking only about type 
conversions and not value conversions (see below), then narrowing 
conversions are only necessary because you've forgotten some important 
bit of type information.  By adding annotations, you can preserve that 
piece of information and thus avoid the conversion and get a program 
that runs fine.

> I worked in signal and image processing for many years and those are
> places where narrowing conversions are used all the time - in the form
> of floating point calculations reduced to integer to value samples or
> pixels, or to value or index lookup tables.  Often the same
> calculation needs to be done for several different purposes.

These are value conversions, not type conversions.  Basically, when you 
convert a floating point number to an integer, you are not simply 
promising the compiler something about the type; you are actually asking 
the compiler to convert one value to another -- i.e., see to it that 
whatever this is now, it /becomes/ an integer by the time we're done.  
This also results in a type conversion, but you've just converted the 
value to the appropriate form.  There is a narrowing value conversion, 
but the type conversion is perfectly safe.

> I can know that my conversion of floating point to integer is going to
> produce a value within a certain range ... but, in general, the
> compiler can't determine what that range will be.

If you mean "my compiler can't", then this is probably the case.  If you 
mean "no possible compiler could", then I'm not sure this is really very 
likely at all.

> Like I said to Ben, I haven't seen any _practical_ static type system
> that can deal with things like this.

I agree.  Such a thing doesn't currently exist for general-purpose 
programming languages, although it does exist in limited languages for 
some specific domains.

-- 
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation



More information about the Python-list mailing list