Search

5/24/2013

functional programming in 5 minutes

λ Function - AKA Anonymous Function originated from a mathematical system called λ Calculus λ Calculus is about simplifying mathematical expressions into λ Expressions to unveil the true nature of underlying computations To achieve this simplification Functions cube(x) = x * x * x are expressed without names (x) → x * x * x ...and can only have 1 argument To handle a multi-argument function it needs to first go through the process of... Currying (n.) A technique of transforming a multi-argument function in such a way that it can be called as a chain of functions, each with a single argument. (x, y) → x + y can be curried into x → (y → x + y) Or, in classical notation f(x, y) = x + y can be curried into g(x) = y → f(x, y) a multi-argument function function(x, y) { return x + y; } when curried, will become a chain of functions, each with a single argument function(x) { return function(y) { return x + y; }; } if we give them names function f(x, y) { return x + y; } then... function g(x) { return function(y) { return x + y; }; } f(1, 2) === g(1)(2);

沒有留言: