Xref: utzoo comp.lang.misc:7055 comp.object:2880 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.misc,comp.object Subject: Re: CHALLENGE: heterogeneous collections Message-ID: <26714:Mar2602:52:1891@kramden.acf.nyu.edu> Date: 26 Mar 91 02:52:18 GMT References: <1991Mar22.210725.29448@neon.S <1991Mar25.220525.11087@leland.Stanford.EDU> Organization: IR Lines: 24 In article <1991Mar25.220525.11087@leland.Stanford.EDU> hoelzle@leland.Stanford.EDU (urs hoelzle) writes: > 2. Here's why you want at least some form of heterogeneous collections: > type T = "some type" > type SubT = "subtype of T" > procedure someProc(c: List[T]) > I think that you'll agree with me that you'd like to use someProc with > a Collection[SubT], especially if someProc just iterates through the > list and sends 'foo' -- after all, every SubT "is a" T. But as soon as > Lists are mutable (e.g. define insert(newElem: T)), the type system > won't let you do it because List[SubT] is *not* a subtype of List[T]. ``Subtype? What's a subtype?'' says the C programmer. To implement a generic list type in C, you use macros. Nowhere is there an explicit ``insert'' operation that demands its own prototypes. So if you do have an operation that works on multiple types, it will work correctly through a list. Maybe one ``object-oriented'' language or another works badly with lists, but that's not related to static versus dynamic typing. So: What use can anyone make of a heterogeneous list? ---Dan