
On Wed, Aug 01, 2012 at 05:53:36PM -0300, Homero Cardoso de Almeida wrote:
I'm trying to learn it, but got stuck when i reached high-order functions. [...] I am a decent C++ programmer.
The C++ analogy is as follows: a high-order function is a function that takes a parameter of a type that has an operator() defined (or returns a value of such a type). For example, find_if [1] is such a "high-order function". ---8<--- struct T { int i; }; class Predicate { public: bool operator()(const T& t) { return t.i == 23; } }; std::vector<T> ts; bool has23() { Predicate pred; return find_if(ts.begin(), ts.end(), pred) != ts.end(); } --->8--- In Haskell the analogous example would be: ---8<--- data T = T Int pred :: T -> Bool pred (T i) = i == 23 ts :: [T] has23 :: Bool has23 = isJust $ find pred ts --->8--- HTH Alex [1] http://www.sgi.com/tech/stl/find_if.html