Malcolm V wrote:
> Using '+' to sum matrices (or any identical mathematical types) is in no
> way what I would consider an example of overloading.
Well both the C2 programming wiki and wikipedia
http://c2.com/cgi/wiki?OperatorOverloading
http://en.wikipedia.org/wiki/Operator_overloading
seem to define it the way I use it.
You're probably refering to what is called parametric polymorphism:
http://en.wikipedia.org/wiki/Parametric_polymorphism
http://c2.com/cgi/wiki?ParametricPolymorphism
> Sure, the compiler can figure that out. What it can't figure out is when
> you accidently pass the wrong operand type to foobar, because the
> various foobars are quite happy to accept a range of different types.
I think you are conflating two separate concepts; dynamic vs static
typing and parameteric polymorphism. These two concepts are are
completely orthogonal.
I do not know of any dynamically typed language which can detect the
passing the wrong operand type to foobar at compile time, but most
dynamically typed languages will detect this kind of error at run time
(one notable counter example is Actionscript in Macromedia Flash).
For statically typed languages, there are two ways handle the situation
where the wrong operand type is passed to foobar; the dumb C++ way where
the compiler will attempt to do an automatic type conversion and
throws and erro if it can't do the conversion and the smart way (Ocaml,
Haskell SML and probably others do it this way), throwing a compile time
error say that the operand is not valid for the function.
> Also anyone who has to debug or maintain the code now has to keep track
> of the operand types, rather then have the compiler do it for them,
> isn't that what you were trying to avoid?
Parametric polymorphism can be abused. Having two functions
defined as (in C++):
int foobar (int x, const char *name, float f) ;
double foobar (double * array, int len) ;
is plain stupid.
There are however perfectly valid and useful uses of parametric
polymorphism, for instance the compare function in Ocaml which
is defined as:
val : compare 'a -> 'a -> int
The C++ example of this would be (I think):
tempate <typename T>
int compare (T a, T b) ;
The Ocaml version is a generic function which can compare both
intrinsic types as well as user defined types (unlike the C++
version which would require the programmer to instantiate versions
of the compare function for all types T needing a compare function).
> As a side note, the difficulties/pitfalls of using an interpreter
> instead of a compiler should start to become apparent.
I am definitely not an advocate of dynamically typed languages.
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"It's far too easy to make fun of Microsoft products, but it takes a
real man to make them work, and a god to make them do anything useful"
-- Anonymous
_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders