3 ms·
(1 % 2) :+ (1 % 2) Gives much more useful information than: <__main__.Qsqrt5 instance at 0xffee4d6c> In fact, it encodes the same information given by yo
by groovy2shoes 13y ago
(1 % 2) :+ (1 % 2)
Gives much more useful information than:
<__main__.Qsqrt5 instance at 0xffee4d6c>
In fact, it encodes the same information given by your __str__ with the added benefit that it can be read back into a Q5 value:
1/2 + 1/2 sqrt(5)
Of course, yours would be nicer to display to someone unfamiliar with Haskell's type constructors. No arguing that. But it's also clear that Haskell's derived show trumps Python's default __str__/__repr__.