Hi there,
I'm writing a parent whose elements contain an attribute called value which is
an Integer. I'd like to have a coercion to the integer. So I wrote the
following in the __init__ method of my parent
mor = Hom(self, IntegerRing())(lambda z: z.value)
mor.register_as_coercion()
self._populate_coercion_lists_()
Now the following works:
sage: NN = NonNegativeIntegers_Alternative()
sage: x = NN.an_element()
sage: ZZ(x)
42
But
sage: Integer(x)
Traceback (most recent call last):
...
TypeError: unable to coerce <class
'sage.categories.examples.infinite_enumerated_sets.NonNegativeIntegers_Alternative_with_category.element_class'>
to an integer
Is it possible to declare a coercion to a type (Integer) as opposite to a
parent ? Am I doing something wrong ? Thanks for your help.
Cheers,
Florent
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---