I don't know which version is correct, but the program below compiles fine and works with g++-3.4.2, but fails with the following error message when compiled with g++-4.1.0...
example.cpp: In function 'typename compose<Coll, Out>::type fmap(typename compose<Tem, Base>::type, Out (*)(In)) [with Coll = TemList<std::list, NullType>, In = int, Out = int]': example.cpp:59: instantiated from here example.cpp:37: error: no matching function for call to 'fmap(const int&, int (*&)(int))' Thanks, Greg Buchholz #include<iostream> #include<list> #include<iterator> using namespace std; class NullType {}; template<template<class>class H, class T> struct TemList { typedef T Tail; }; template<class Tem,class Base> struct compose; template<template<class>class Tem,class Base> struct compose<TemList<Tem,NullType>,Base > { typedef Tem<Base> type; }; template<template<class>class Tem,class Tail, class Base> struct compose<TemList<Tem,Tail>,Base > { typedef Tem<typename compose<Tail,Base>::type> type; }; template<class Coll, class In, class Out> typename compose<Coll,Out>::type fmap(typename compose<Coll,In>::type l, Out (*f)(In)) { typename compose<Coll,Out>::type temp; for(typename compose<Coll,Out>::type::const_iterator iter = l.begin(); iter != l.end(); ++iter) { temp.push_back(fmap(*iter,f)); } return temp; } template<class In, class Out> Out fmap(In i, Out (*f)(In)) { return f(i); } int inc(int x){ return x+1; } template<class T> std::ostream& operator<<(std::ostream&, const std::list<T>&); int main(int argc, char* argv[]) { int tmp[] = {1,2,3}; list<int> simple_list(tmp,tmp+3); cout << "fmap on single int :" << fmap(5,inc) << endl; cout << "inc of simple list: " << simple_list << " => " ; cout << fmap<TemList<list, NullType>,int,int>(simple_list,inc) << endl; return 0; } template<class T> std::ostream& operator<<(std::ostream& o, const std::list<T>& l) { o << "["; for(typename std::list<T>::const_iterator i = l.begin(); i != --l.end(); ++i) o << *i << ","; return o << *(--l.end()) << "]"; }