[Python-3000] PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities) (original) (raw)

Jason Orendorff jason.orendorff at gmail.com
Wed Apr 25 19:27:31 CEST 2007


On 4/25/07, Collin Winter <collinw at gmail.com> wrote:

I can see use-cases for this level of formalism, but I'm a strong -1 on making any part of the stdlib effectively off-limits for people without advanced math degrees. Why can't this be shipped as a third-party module?

I agree. That last question says something interesting about ABCs, though. You and I don't care about Rings, but some people do, and they would probably like this as a third-party library... if it were possible.

In Haskell, you can define a typeclass (which is a lot like an ABC):

class Ring r where
  zero :: r
  add :: r -> r -> r
  negate :: r -> r
  mul :: r -> r -> r

Then you can declare that certain existing types, even builtin types, conform to it:

-- tell Haskell that "the Integer type is a Ring"
instance Ring Integer where
  zero = 0
  add x y = x + y
  negate x = -x
  mul x y = x * y

This feature makes stuff like NumericPrelude possible.

My understanding is that Guido's ABCs won't support this, so in fact you couldn't ship Jeffrey's numeric classes as a third-party library.

(My perspective is a little different from Jeffrey's. Maybe Haskell does draw fire for not having a ton of numeric typeclasses; I don't know. But it seems to me Haskell gets it Just Right: the standard typeclasses are simple, practical, and loose enough to accomodate Int and Float; and the language lets you roll your own crazy mathematical mojo if that's what you like.)

-j



More information about the Python-3000 mailing list