3 ms·
> rather than “for” loops, it’s often easier to think in terms of the common patterns: “map”, “reduce”, “filter”. It is. My lament there is that, at least in
by bunderbunder 12y ago
> rather than “for” loops, it’s often easier to think in terms of the common patterns: “map”, “reduce”, “filter”.
It is. My lament there is that, at least in my experience, optimizers haven't caught up in this department. So while I invariably start with the higher-order operations, all too often the profiler subsequently informs me that I need to replace that code with a for loop.
I suspect that side effects are the culprit there: In a language without referential transparency, the optimizer's very limited in what kinds of reasoning it can make about a function. I'm not quite ready to give up side effects just yet, though. I wish I could work in a language that only allows them in functions that explicitly declare that they want to use them, though.
- evincarofautumn 12y ago> I wish I could work in a language that only allows them in functions that explicitly declare that they want to use them, though. That’s what Haskell does. The big scary M-word just gives you all the other features you end up wanting from your effect system once you have one. See my explanation here: http://programmers.stackexchange.com/questions/258011/alternative-to-language-purity/258033#258033 http://programmers.stackexchange.com/questions/258011/altern...
- codygman 12y agoHaskell and steam fusion will turn them into iterative loops for you automatically ;)
- JadeNB 12y agoJust in case anyone is confused (I did a double take), I think that you mean stream fusion (http://google.com/search?q=Haskell%2Bstream%20fusion http://google.com/search?q=Haskell%2Bstream%20fusion).