Type parameters

Nicolas Cannasse ncannasse at motion-twin.com
Wed Sep 6 07:41:22 PDT 2006


>>Fortunately, there is already big a good amount of papers written on
>>both implementation and correctness of bounded type-parameters. That
>>disables at least the first two points.
> 
> 
> Can you give some references?

I don't have any link there, but I assume that the appropriate work has
been done before (and completed after) integration of bounded type
parameters in Java.

>>than a OO one. Plus, unless you have proper functional types and at
> 
> 
> We do have functional types. I realize the wiki is a bit disorganized 
> (sorry about that, we're reorganizing it little by little), but the type 
> system does include structural types for functions, arrays, objects, and 
> unions.

Yes, this is something that I didn't know.
Can I find somewhere the references for these ?

>>least a bit of type inference, it's very difficult to have everything
>>being sound.
> 
> 
> I don't know what you mean; inference may be a handy tool, but it isn't 
> required for type soundness.

Sure. But when you deal with type parameters, it surely helps to cleanup
the resulting program ;)

> They are certainly a concise way of expressing this, but Graydon's point 
> is that if they are only a small improvement over the equivalent program 
> written with unbounded types, then they aren't worth the overhead. After 
> going through the examples above, it seems to me that the approach of 
> passing additional operations as extra arguments scales up just fine, 
> requiring no more than a small, fixed amount of extra code for each 
> additional operation than the solution with bounded polymorphism.

Having programmed in OCaml for many years, I understand how HOF can be
used to replace bounded types. However there are some restrictions to this :

- such API methods needs to be passed to the constructor, they are not
par of the type "per-se". In particular, let's say you want to get the
intersection of two Maps. This operation is sound only if both maps have
been constructed with the same function for generating keys. With
bounded type parameters, you can tie the type and the function together
(unless you allow variance which would allow overriding, but then the
semantic is also different).

- it doesn't work well with interfaces. People might already use
IComparable or such interfaces in their architecture. They will have
then to rewrap their methods into static functions for the sake of
changing paradigm (from OO to functional).

While i love Functional programming a lot, I'm not sure this is the
correct way to deal with the problem in a OO world such as ES4.

Nicolas



More information about the Es4-discuss mailing list