[Python-3000] PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities) (original) (raw)
Jim Jewett jimjjewett at gmail.com
Wed Apr 25 23:23:25 CEST 2007
- Previous message: [Python-3000] PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)
- Next message: [Python-3000] PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4/25/07, Jeffrey Yasskin <jyasskin at gmail.com> wrote:
class MonoidUnderPlus(Abstract):
Is this useful? Just because two things are both Monoid instances doesn't mean I can add them -- they have to be part of the same Monoid. By the time you do
assert isinstance(a, MonoidUnderPlus)
assert isinstance(b, MonoidUnderPlus)
assert isinstance(a, b.__class__) or isinstance(b, a.__class__)
I'm not sure how much you've really saved.
Open issue: Do we want to give people a choice of which of the following to define, or should we pick one arbitrarily?::
def neg(self): """Must define this or sub().""" return self.zero() - self
def sub(self, other): """Must define this or neg().""" return self + -other
Probably better to pick one; then it is clear that they have to override something, and there won't be as many accidental infinite loops. If they really want to define the other, they can just do
def __neg__(self):
super(_this_class__, self).__neg__()
The decorator doesn't know it isn't a real override.
-jJ
- Previous message: [Python-3000] PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)
- Next message: [Python-3000] PEP 31XX: A Type Hierarchy for Numbers (and other algebraic entities)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]