🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #3200

Re: CHALLENGE: heterogeneous collections

#3200
From: Hans Boehm
Date: Tue, 26 Mar 1991 18:13
29 lines
2156 bytes
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 <x: T, T: [algebra containing foo]>.)

Hans-J. Boehm
(boehm@xerox.com)
Technical Details
Message-ID: <boehm.670011223@siria>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!parc!boehm
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> <jls.669591628@rutabaga> <1991Mar22.210725.29448@neon.Stanford.EDU> <1991Mar25.220525.11087@leland.Stanford.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <boehm.670011223@siria>
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> <jls.669591628@rutabaga> <1991Mar22.210725.29448@neon.Stanford.EDU> <1991Mar25.220525.11087@leland.Stanford.EDU>
Sender: news@parc.xerox.com
Organization: Xerox PARC
Lines: 29