[comp.lang.smalltalk] Polymorphic type checking

db@lfcs.ed.ac.uk (Dave Berry) (03/29/90)

In article <14488@cbnewsc.ATT.COM> lgm@cbnewsc.ATT.COM (lawrence.g.mayka,ihp,) writes:
>In article <6143@crdgw1.crd.ge.com> chao@sunflower.crd.ge.com (William Chao) writes:
>>In the paper "Basic Polymorphic typechecking," by Luca Cardelli,
>>Science of Computer Programming 8 (1987) pp. 147-172. On page 150:
>>-----------------------------------------------------------------------
>>Polymorphic type systems try to reconcile these two goals
>>by providing all the safety of statically typed languages,
>>and most (but not all) the flexibility of untyped languages.
>>-----------------------------------------------------------------------
>>My 1st question: Why he says "but not all?"
>
>Languages without mandatory compile-time typing, such as Common
>Lisp, are able to manipulate information elements of
>heterogeneous, unrelated types in a uniform manner.

This is also true - in fact more true - of a language with bounded
polymorphism.  Using such a language you could declare a list of type
ANY LIST, where ANY is the root of your inheritance tree.  Any objects
could be added o such a list, and be manipulated uniformly.  Moreover,
any operations that the type system let you apply to elements of the
list would be guaranteed to be defined for all objects on the list.
This last point is not true of Common Lisp.

However, such a language would not allow you to take the head element
of a list and manipulate it with operations appropriate to its type
unless those operations were appropriate to all types.  In other words,
you would lose type information by adding the object to the list.
By contrast, all type information in Common Lisp is checked at run-time
(well, usually), so no type information would be lost.

Cardelli's approach to this is to have a special type DYNAMIC which
links run-time type information to an object for the rare cases in
which it is needed.

 Dave Berry, LFCS, Edinburgh Uni.      db%lfcs.ed.ac.uk@nsfnet-relay.ac.uk

   "Excuse me, Mr. Policeman, but someone seems to have stolen my soul.
    What're you going to do about that then, Officer?" -- Here and Now.