On 1/17/06, Raymond Hettinger <[EMAIL PROTECTED]> wrote: [snip] > I don't see a way around creating an integer recognition tool that > doesn't conflate its terminology with broadly-held, pre-existing math > knowledge: complex is a superset of reals, reals include rationals and > irrationals some of which are trancendental, and rationals include > integers which are an infinite superset of non-negative integers, whole > numbers, negative numbers, etc. > > The decimal class only makes this more complicated. All binary floats > can be translated exactly to decimal but not vice-versa. I'm not sure > where they would fit into a inheritance hierarchy.
To repeat a popular suggestion these days, python might borrow a page from Haskell. Haskell's Prelude_ defines a number (pardon the pun) of numeric typeclasses, each of which requires certain members. The inheritance graph shapes up roughly like this: Num - the ur-base class for all numbers Real - inherits from Num Integral - inherits from Real. Integral numbers support integer division Fractional - inherits from Num. Fractionals support true division Floating - inherits from Fractional. Floating-class objects support trigonometric and hyperbolic functions and related functions. RealFrac - inherits from Real and Fractional. This is used to operate on the components of fractions. RealFloat - inherits from RealFrac and Floating, providing efficient, machine-independent access to the components of a floating-point number. While it may not be necessary to concoct that many base classes for python, having a solid selection of such classes to subclass would reduce the need for heuristics like attribute testing. Moreover, subclassing a (or several) numeric type classes makes your intentions explicit, rather than relying on testing for an "implicit interface". Given the impact this would have on legacy code, and the need to refit the built-in types and standard library, such a chance might be better put off until Python 3k. _Prelude - http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html Thanks, Collin Winter _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com