What happens if you don't have all the arguments handy for a function, but you want to give whatever arguments you do have now and then provide the rest of them to the function later? This is called currying, and is a core concept in functional programming. It's messy, but possible to curry functions in PHP now that closures have been added.

First, let me show you how currying looks in a functional language. Here's a basic example in OCaml/F#:

let do_math op x y =

match op with

'+' -> x + y

| '-' -> x – y

| _ -> failwith "Invalid op"

let add = do_math '+'

let inc = add 1

let dec = add (-1)

;;

A function named do_math is defined that accepts an operator and two operands. The function's return value will be either the sum or difference of the operands, depending on whether the given operator is + or -. Notice how do_math is then called with a single argument. OCaml doesn't raise an error; it simply returns a function …

First, let me show you how currying looks in a functional language. Here's a basic example in OCaml/F#:

let do_math op x y =

match op with

'+' -> x + y

| '-' -> x – y

| _ -> failwith "Invalid op"

let add = do_math '+'

let inc = add 1

let dec = add (-1)

;;

A function named do_math is defined that accepts an operator and two operands. The function's return value will be either the sum or difference of the operands, depending on whether the given operator is + or -. Notice how do_math is then called with a single argument. OCaml doesn't raise an error; it simply returns a function …