Xref: utzoo comp.lang.misc:7080 comp.object:2893 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!parc!boehm From: boehm@parc.xerox.com (Hans Boehm) Newsgroups: comp.lang.misc,comp.object Subject: Re: CHALLENGE: heterogeneous collections Message-ID: Date: 26 Mar 91 18:13:43 GMT References: <22032@yunexus.YorkU.CA> <11820:Mar1923:59:3591@kramden.acf.nyu.edu> <19MAR91.22493670@uc780.umd.edu> <18271:Mar2013:19:1091@kramden.acf.nyu.edu> <1991Mar20.214231.3411@neon.Stanford.EDU> <1991Mar22.210725.29448@neon.Stanford.EDU> <1991Mar25.220525.11087@leland.Stanford.EDU> Sender: news@parc.xerox.com Organization: Xerox PARC Lines: 29 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]. As someone who hasn't yet completely converted to the object oriented religion, this has always struck me as using the wrong tool for the job. I really don't want a "list of T or subtype of T". I want a "list of objects that understand foo". Once I take that view, I have no problems, at least in the few statically typed languages that allow this (e.g. Russell, and probably FX from MIT, and probably Scratchpad II from IBM). I also don't need to construct my types in such a way that all types that understand foo are "derived" from a common supertype; I can use inheritance purely where it simplifies the implementation. And I get full static checking, though elements of the list will, of course, somehow carry the "foo" function with them. (In Russell, I would build a list of pairs .) Hans-J. Boehm (boehm@xerox.com)