
On Thursday, September 15, 2011 12:31:50 PM David Sankel wrote: <snip>
I'm the one who designed the DeBruijn bind syntax and implementation that Dave A and Larry referenced. The DeBruijn bind syntax would work for compile time or run time. The sample implementation was for run time.
DeBruijn bind syntax can represent strictly *more* functions than the traditional bind syntax, even with protect. Furthermore, the functions that DeBruijn bind can define, that traditional bind cannot, are useful and interesting.
An example is the flip function:
haskell syntax:
flip :: ((a,b) -> c) -> ((b,a) -> c) flip f (x,y) = f (y,x)
intuition:
flip is a function that takes in a two-argument function and returns a two-argument function that is essentially the same, but the arguments are reversed.
<snip>
<rant> Unfortunately traditional bind syntax and it's inherent design flaws has been replicated in several other libraries like mpl, lambda, phoenix, and C++-0x (arg!). It should be noted though that phoenix users can get around this somewhat by using _identifier syntax. </rant>
#include <boost/phoenix.hpp> #include <iostream> namespace phx = boost::phoenix; int main() { using phx::placeholders::_1; using phx::placeholders::_2; using phx::local_names::_a; using phx::local_names::_b; using phx::val; using phx::lambda; auto f = std::cout << _1 << _2 << "\n"; auto flip = lambda(_a = _1)[bind(_a, _2, _1)]; auto flipped_f = flip(f); flipped_f("David.", "Thanks for your unqualified rant, "); } Output: Thanks for your unqualified rant, David.