4 ms·
Partial Function Application
- ktpsns 4y agoI find the point-free function composition style so much more elegant then lambda functions. I acknowledge lambda functions are easier to read and work basically the same way in most contemporary multi-paradigm programming languages.
- vore 4y agoPoint-free composition can be more expensive and hard to optimize compared to anonymous functions, since you're now having to carry a heap-allocated closure around if you've partially applied arguments. Anonymous functions by contrast in C++ are super explicit about what they're capturing and you can be more sure of the allocations.
- gpderetta 4y agoStd::bind, assuming that's what the parent was referring to, does no heap allocation.
- deleted 4y ago[deleted]
- l- 4y agoAs long as elegance is not solely length using certain combinatory representations like SKI: (S(K(SI))(S(KK)I)) :: λxy.yx
- gpderetta 4y agoI expected to keep using boost::bind (and std::bind) even after we got lambdas in C++11. I don't think I have actually used them in years. Even though they can be succinct, they have some sharp corners and a non-trivial compilation time cost. In practice lambdas are good enough in almost all cases.
- metadat 4y agoIn the article example: double divMe(double a, double b){ return double(a/b); } The "return double(a/b)" is excessive, right? Returning a/b has the same effect, and I'd expect they compile to the exact same thing in this particular case. Is there a reason to prefer the extra verbose version? The excessive redundancy irks the perfectionist in me.
- ubavic 4y agoSentence 'Therefore, a programming language such as Haskell has only functions taking one argument.' is a little bit misleading. Haskell perfectly fine handles multi-argument functions. It even has functions `curry` and `uncurry` in the Prelude.
- afiori 4y agoA tuple is still a single value f x has a single argument, even if x is (a, b)
- sudosysgen 4y agoNot really. A Haskell function takes a single argument. Currying works by partial application from left to right. f a b would then be equivalent to (f a) b such that (f a) evaluates to a new function which takes a single argument. 'curry' and 'uncurry' allow to go to and from this way of handling arguments instead of using tuples. But tuples are also a single value, and this is actually very important - you won't be able to change a single 'argument' without creating a new pair, for example. There is no way to have a real multi argument function.