Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!news.sprintlink.net!news-peer.sprintlink.net!howland.erols.net!vixen.cso.uiuc.edu!uchinews!not-for-mail
From: Tim Pierce <twpierce+usenet@mail.bsd.uchicago.edu>
Subject: Re: inconsistent polymorphism in scheme?
X-Advocacy: support the Equal Rights Marriage Project: 1-900-97-MARRY ($5/call)
X-Nntp-Posting-Host: bio-5.bsd.uchicago.edu
Message-ID: <DzEowB.Iqx@midway.uchicago.edu>
Originator: twpierce@mail.bsd.uchicago.edu (Tim Pierce)
Sender: news@midway.uchicago.edu (News Administrator)
Organization: Direct Frontal Assaults on Bob Dornan
References: <53r447$b4a@cerberus.ibmoto.com> <9610141905.AA06452@quilty.Stanford.EDU> <izbue29b42.fsf@shin.CS.Princeton.EDU>
Date: Thu, 17 Oct 1996 06:04:59 GMT
Lines: 46

In article <izbue29b42.fsf@shin.CS.Princeton.EDU>,
Matthias Blume <blume@shin.cs.princeton.edu> wrote:

>However, I feel that the analogy the original poster was
>making -- between different number `types' and different types like
>`string' and `vector' -- is quite inaccurate.  ...  An integer
>in Scheme _is_ also a real (even though it might internally be
>represented in a different way), so the + operation should (of course)
>work on both the same way.  A string, on the other hand, is _not_ a
>vector (even though it might internally be represented the same way).

Emacs Lisp addresses this issue by denoting strings, lists and
arrays to be `sequences', and designating some functions (of which
I believe `length' is one) as sequence functions, which may take
any sort of sequence as their argument.

I'm not advocating applying this approach in Scheme -- only making
an observation about how other languages have dealt with this
issue.

>So, with the existence of
>improper lists, what should `length' return for them?  I'd like to see
>an invariant like
>
>	(= (length x) (- (length (cons 0 x)) 1))
>
>to hold for all x.  Now, if `length' were `polymorphic', and `x' were
>a string, say "foo", then
>
>	(length x) --> 3
>	(- (length (cons 0 x)) 1) --> 0
>
>You get the picture.

The `invariant condition' here presupposes that x will always be a
list.  (No?  It compares the value returned by applying `length'
to `x' with the value returned by applying `length' to a pair.)
If we are to hypothesize that x may be some non-list object, that
presupposition doesn't make sense -- it denies the polymorphism
out-of-hand.

-- 
"A person who dies of lung cancer at age 70 will not be hospitalized later
with another disease," said a study released Thursday by [Canada's] Imperial
Tobacco touting the benefits of early death in smokers on the health-care
system.  (Reuters, in the Chicago _Tribune_, 9/3/94)
