I would say it is a bit like Once and Only Once
In C / C ++, I find myself writing code like
configure_grid (grid, first_column, last_column, action) { for (i = first_column; i <= last_column; ++i)
Instead of writing for-loop once for each of alpha and beta. This is similar to considering procedural code. The advantage here is clear.
Currying is an important theoretical concept, but from a practical point of view it is an advantage.
In fact, I remember once writing a test suite in C, it was something like this:
typedef bool (*predicate) (const type *); const char * argument; bool do_foo (const type * t) { return bar (t, argument); } bool do_baz (const type * t) { return bap (t, argument); } predicate foo (const char * arg) { argument = arg; return do_foo; } predicate baz (const char * arg) { argument = arg; return do_baz; } assert (for_all (data_set("alpha"), foo ("abc"))); assert (for_all (data_set("beta"), baz ("def")));
All this was in pure C, without macro definition, etc. Functional style and kind of like currying. The advantage here is that you can immediately see what the test cases are. data_set similar - it associates its argument with another function that retrieves data: for_all executes thunk, checks the predicate, and clears. Tidy.
source share