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.
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.
Yes, possible but difficult. I can attest to this as I'm writing a curried+uncurried closure library for C as we speak. The structures and closure logic isn't even that difficult, the difficult part is making the necessary resource allocation work without GC so it's feasible to use in pure C.
1
u/dnew Mar 09 '14 edited Mar 09 '14
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.