Am 20.09.2017 um 16:27 schrieb Станислав Черничкин:
I've wrote simple Haskell benchmark program, ... which means that the result is not really meaningful.
Large programs have their inefficiencies in needless recomputations, which happen as soon as no single programmer knows everything anymore and people start reinventing the wheel. Small programs do not need to be particularly efficient. Well, usually - sometimes they need to be, but these cases are very rare. In your particular case, the base cause was that your mental model of what Haskell was doing did not match what was really happening. This misdirected you to the wrong function and gave you surprising results. This is not your fault. Haskell's execution model is fundamentally different from that of most other languages, and it takes time and experience to explore all the consequences. It is not Haskell's fault either, either - Haskell was built to explore specifically this execution model. My impression is that it makes Haskell's performance somewhat less predictable, but allows you to build larger systems that "just work" - millions of line of code, instead of the few thousands that you get with typical imperative code. Of course, these things become noticeable only if you (a) have worked on software that is substantially larger than a few thousand lines of code, and (b) at least one of these projects was in Haskell, or any other language with good support for referentially transparent functions. I wouldn't concentrate on getting that benchmark fast. It's too early to get any meaningful data out of that. Essentially, while you can speed up Haskell that way, you are going towards a more imperative style, and you'll lose the real advantages of Haskell. For this reason, I wouldn't pursue those monad library functions. Not right now, anyway; they are pretty specialized, and you should have a better reason than performance to get back to them. If you wish to explore performance, try to make your code faster without too much library function use. You will get more surprising results, but you will get a better understanding of what happens. HTH Jo