Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!icdoc!qmw-cs!eliot From: eliot@cs.qmw.ac.uk (Eliot Miranda) Newsgroups: comp.object Subject: Re: A Hard Problem for Static Type Systems Message-ID: <3617@sequent.cs.qmw.ac.uk> Date: 29 Apr 91 15:34:56 GMT References: <1991Apr25.011607.25536@leland.Stanford.EDU> Organization: Computer Science Dept, QMW, University of London, UK. Lines: 37 In article you write: >It's not entirely clear to me what you're trying to achieve by viewing >integer and float as subtypes of number. They presumably share no code, >hence code reuse is not the issue. They most certainly can. In Smalltalk-80's arithmetic implementation class Number provides a number(sorry) of arithmetic operators defined in terms of other (presumed more primitve operators). e.g. Number abs ^self < 0 ifTrue: [self negated] ifFalse: [self] e.g. quo: (rounding division towards zero), // (rounding division towards -ve infinity) are implemented in Number in terms of / (exact division) floor & ceiling. Number provides the specification & implementation of the coercion system which allows mixed arithmetic. Number provides generic implementations of many functions implemented by float, e.g. Number cos ^self asFloat cos Number provides enumeration & interval creation: to: to:by: to:by:do: etc At least in Smalltalk, using a class hierarchy that requires subclasses to implement a certain subset of operators & then implementing other operators implemented upon them higher in the hierarchy is a common & powerful technique. The canonical example is the implementation of the relational operators > >= <= ~= min: max: between:and: etc in Magnitude in terms of = < and not. -- Eliot Miranda email: eliot@dcs.qmw.ac.uk Dept of Computer Science ARPA: eliot%dcs.qmw.ac.uk@nsf.ac.uk Queen Mary Westfield College UUCP: eliot@qmw-dcs.uucp Mile End Road Fax: 081 980 6533 (+44 81 980 6533) LONDON E1 4NS Tel: 071 975 5229 (+44 71 975 5229)