🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #3313

Re: CHALLENGE: heterogeneous collections

#3313
From: Erland Sommarskog
Date: Sun, 31 Mar 1991 21:11
42 lines
1828 bytes
Also sprach Urs Hoelzle (hoelzle@leland.Stanford.EDU):
>	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].

In which type system? If you imply the type system in any statically
typed language, I have news for you. The Eiffel code below compiles 
and executes just fine. For those of you who are unacquainted with the
kernel library, I should add that STRING is an heir of COMPARABLE.
(I assume when you talk of subtype you mean something like an heir.)

CLASS Subtype

FEATURE

Some_proc(L : Linked_list[Comparable]) : boolean IS
REQUIRE L.count >= 2;
DO
  Result := L.first < L.last;
END;

CREATE IS
LOCAL L : Linked_list[String];
      X : boolean;
DO
  L.create;
  L.Put_left("First");
  L.Put_left("Last");
  X := Some_proc(L);
  Io.putbool(X);
END;

END;
-- 
Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se
Technical Details
Message-ID: <3112@enea.se>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!enea!sommar
References: <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!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!enea!sommar
From: sommar@enea.se (Erland Sommarskog)
Newsgroups: comp.lang.misc,comp.object
Subject: Re: CHALLENGE: heterogeneous collections
Message-ID: <3112@enea.se>
Date: 31 Mar 91 21:11:01 GMT
References: <jls.669591628@rutabaga> <1991Mar22.210725.29448@neon.Stanford.EDU> <1991Mar25.220525.11087@leland.Stanford.EDU>
Organization: Enea Data AB, Sweden
Lines: 42