evan_tech

Previous Entry Share Next Entry
11:15 am, 4 Aug 04

lambdas

I remember when I first started really using ML I found the function parameter order kinda weird. Operations like List.map took the list as their last argument, even though the object-oriented style I'm accustomed to (C, Python, etc.) puts the object first. I initially wrote it off to weirdness (after all, the C library functions like fwrite() take the FILE* as their last argument), but then I eventually realized how useful it is when combined with currying.

I've been using R lately, which lacks currying, and I keep needing to write lambda expressions like this (the syntax for lambdas is "function(x) expr"):
f(data, function(x) g(x, function(y) h(y, someconstant)))
Here, the data being passed through is the first arguments of these functions (which do things like map, etc.), and so R chose to make it the first arguments.
If the functions were curried and took their arguments in the other order, I could do something like this:
(f (g (h someconstant))) data
which is a lot simpler.

Though I admit neither makes much sense as I write them here. They're easier to understand in context. :)