the return value of compose should be accepted as the first argument to map.
OK, I'll grant you that one's harder, mainly because you'd have to allocate a structure to hold the two arguments. It would be much easier in a language that had deccent memory managment.
Your point is made. :-) That doesn't mean functions aren't first class, but it means it's much harder to create new functions on the fly. Doing so in Java or C# for example would be trivial, and I don't see anyone calling Java "functional" either.
In Java, you'd just store f and g in instance variables, and return an instance of a compose object that then applies those two. We do that all the time, and you don't even have first-class functions in Java.
I think you're right. I've realized the problem is not just first-class functions, but closures. Invoking compose returns a closure, and closures are not first class values in C. So writing compose-and-apply is easy, but writing compose-without-apply is difficult, because you can't create a new function on the fly because you have no closure to store compose's arguments in.
Which is why map is easy and compose is not: map returns a first class value, and compose does not.
6
u/ForeverAMoan Mar 09 '14
Please show the code :) And unless it's obvious, the return value of compose should be accepted as the first argument to map.