4 ms·
Haskell has way too much syntactic sugar some of the time, but I really appreciate its anonymous function syntax. If I need a quick-and-dirty map over a list o
by artemisyna 8y ago
Haskell has way too much syntactic sugar some of the time, but I really appreciate its anonymous function syntax.
If I need a quick-and-dirty map over a list of something, a
(\x -> x + 1) a
is much nicer than a
std::for_each(a.start(), a.end(),
[](float x) {
return x + 1;
} // end of lambda expression
)
or whatnot that I have to do in C++.
- stochastic_monk 8y agoYou're really looking for `std::transform`. On the other hand, for(auto it(a.start()); it < a.end(); ++(*it++)); and for(auto &el: a) ++el; aren't terribly verbose.
- nicoburns 8y agoJavaScript lets you do: a.map(x => x + 1) which is pretty nice. And Rust lets you do: a.map(|x| x + 1) C++ syntax is just awful, and especially for functional stuff.
- himom 8y agoSwift closure syntax, at least in <= 2.0, made for awkward API calls, since it wasn’t clear whether inline or after closures were used. In Ruby, a.map(&:succ)
- steveklabnik 8y agoIf you have a named function, rust lets you do a.map(succ) as well, since functions can be used where closures can, as long as the types work.
- jeffmcmahan 8y agoSame in JS
- erik_seaberg 8y agoI'm still surprised Haskell is the only language I've ever seen in which the "add 1 to your argument" function is simply (+ 1)