4 ms·
The "deriving (Show)" gives you __repr__ and __str__ for free in Haskell.
by groovy2shoes 13y ago
The "deriving (Show)" gives you __repr__ and __str__ for free in Haskell.
- jordigh 13y agoIt gives you a default that isn't very pretty. Python also has a default that isn't very pretty.
- 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__.