[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Language War (Re: "C" Manual)



On Tue, 1 Jan 2002, Richard Cobbe wrote:

> > | Casting you can't really get away from nor do you really need to.  In fact
> > | the more strongly typed the language is, the more casting you have to do.
> > 
> > This statement is incorrect.
> 
> Agreed.

I suppose I will agree as well, I was not meaning to include dynamically
typed languages in the original statement, I just didn't say that :}
Really it was not a very good statement to make, although in the original
context it wasn't so bad :}

> However, I think that the flexibility of a type system is more
> important than its `strength' for removing the need for casts.

I will go along with that as well.  In ML for instance (and other
languages as well) there is parametric polymorphism which give you a lot
of the flexibility of dynamic typing while still retaining much of the
error checking of static typing.  This is different from the
"polymorphism" found in C++ in which you can have virtual functions (which
still require the programmer to provide all the different implementations)
and inheritance (which only permits polymorphism within a very limited set
of types).  Although I do not know Haskell my understanding is that this
is how it works as well.

For instance you could have:
fun times x y = x * y;

You could then apply this function to either reals, ints, or one of each
and then it would return the appropriate type.  The compiler will trace
the execution through the function, deducing which are legal types from
the operators and functions used within the function.  In this way you do
not need to write a separate function for each combination of types your
functions might want to operate on, even though ML is a statically typed
language.

But because the checking is all done at compile-time you do not have much
risk of runtime errors due to type problems.



Reply to: