Related articles |
---|
Seeking brief description of the benefits of Type Inference david.witten@template.com (1997-05-12) |
Re: Seeking brief description of the benefits of Type Inference salomon@nickel.cs.umanitoba.ca (1997-05-13) |
Re: Seeking brief description of the benefits of Type Inference djw@cis.ksu.edu (Derek J. Witt) (1997-06-13) |
From: | salomon@nickel.cs.umanitoba.ca (Daniel J. Salomon) |
Newsgroups: | comp.compilers |
Date: | 13 May 1997 22:57:45 -0400 |
Organization: | Computer Science, University of Manitoba, Winnipeg, Canada |
References: | 97-05-144 |
Keywords: | types, optimize, books |
David Witten <david.witten@template.com> wrote:
|> I don't know ML (or any other language that has type inference), and so
|> don't know why type inference is good. Other than obviating the need
|> to declare the type of constructs what are the benefits of it to the
|> work-a-day programmer/maintainer?
As an example of type inference used outside of ML, C++ uses type
inference to instantiate function templates. Consider the following
C++ function template:
template <class T>
void insert0(T a[], T *b)
{
T temp;
temp = *b;
a[0] = temp;
}
This function could be called with the statements:
int k=20;
int i[10] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, *j=&k;
insert0(i,j);
When the function insert0 is invoked, C++ will use the type of the
actual arguments to infer the type of the local variable temp. In
this case it will infer that temp has type "int."
|> Could someone tell me an on-line reference that will answer my
|> question?
I don't know of an on-line reference, but the book "Compilers:
Principles, Techniques and Tools" by Aho, Sethi, and Ullman gives an
introduction to type inference in sections 6.6 & 6.7, along with
references to other works.
--
Daniel J. Salomon -- salomon@cs.UManitoba.CA
Dept. of Computer Science / University of Manitoba
Winnipeg, Manitoba, Canada R3T 2N2 / (204) 474-8687
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.