Followed 3 functions written in Haskell language, which are fac1, fac2 and fac3. They are all for calculating factorial. The performance of them are different.
'fac1 10000' takes (0.97 secs, 104695704 bytes)'fac2 10000' takes (1.04 secs, 115210800 bytes)'fac3 10000' takes (0.52 secs, 113564104 bytes)
The performance differences are because of many facts of Haskell language, including Tail Recutsion and Lazy Evaluation.
'fac1' is not tail-recursive, while 'fac2' and 'fac3' are tail-......
阅读全文