Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I aimed for clarity and some extra features in mine (e.g. __repr__ and __str__) instead of code golfing it. I also used the actual Binet formula instead of just approximation.

The only big Haskell feature here is a default implementation of binary exponentiation, but this is a library feature, not an innate feature of the language. It would be easy enough to augment existing standard Python libraries with such a corresponding feature.



It wasn't meant to be a criticism of your implementation - just a comparison of the two languages for this particular task. Haskell happens to be very concise for writing mathematical code. I love Python too, but for different reasons (easy to prototype, great libraries, flexible).

I've noticed that people with a mathematical background tend to be very attracted to Haskell. There's a great blog post by Dan Piponi enumerating eleven reasons to use Haskell as a mathematician:

http://blog.sigfpe.com/2006/01/eleven-reasons-to-use-haskell...


I have a mathematical background, and I am not that attracted to Haskell. And I've tried. It seems that Haskell attracts logicians, which are their own particular subspecies of mathematicians, but I think far more mainstream mathematicians are attracted to Python. Sage is a prominent example of how easy it is for mathematicians to get into Python.


> It seems that Haskell attracts logicians, which are their own particular subspecies of mathematicians

Or perhaps people who care about foundations in general.


The "deriving (Show)" gives you __repr__ and __str__ for free in Haskell.


It gives you a default that isn't very pretty. Python also has a default that isn't very pretty.


    (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__.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: