REVISED: Saturday, September 20, 2025
The name comes from the logician Haskell Curry, who developed the concept.
Uncurried vs. Curried Functions
Let's compare a standard (uncurried) function that uses a tuple with a curried function to see the difference.
A. The Uncurried Approach (Using Tuples)
An uncurried function takes all its arguments bundled together, typically in a tuple.
(* Define a function 'add' that takes one argument: a tuple of two integers
(int * int). *) let add (x, y) =
(* It returns the sum of the two elements from the tuple. *)
x + y;;
(* Call the 'add' function by passing it a single argument: the tuple (3, 4). *)
let result = add (3, 4);;
(* Print the result. Printf.printf is used for formatted printing. *)
(* "%d" is a placeholder for an integer. "\n" is a newline character. *)
Printf.printf "The uncurried result is: %d\n" result;;
(* Expected output: The uncurried result is: 7 *)
In this case, add
has the type int * int -> int
, meaning it takes a tuple of two integers and returns one integer. It must receive both values at the same time.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
OCaml version: The OCaml toplevel, version 5.3.0
Coq-LSP version: 0.2.3
Loading personal and system profiles took 1091ms.
PS C:\Users\User> ocaml C:\AI2025\add1.ml
The uncurried result is: 7
PS C:\Users\User>
B. The Curried Approach (The OCaml Default)
A curried function is defined to accept its arguments sequentially. This allows for a powerful feature called partial application.
(* Define a curried function 'add'. It takes an integer 'x' first. *)
(* It then returns a *new* anonymous function that takes an integer 'y'. *)
let add x y =
(* This inner function's body calculates the sum of x and y. *)
x + y;;
(* Call the function by supplying the arguments one after another. *)
(* 'add 3' is evaluated first. It returns a new function. *)
(* That new function is then immediately called with the argument '4'. *)
let result = add 3 4;;
(* Print the final result to the console. *)
Printf.printf "The curried result is: %d\n" result;;
(* Expected output: The curried result is: 7 *)
Here, add
has the type int -> int -> int
. This can be read as int -> (int -> int)
. It means:
add
is a function that takes anint
.It returns a new function of type
int -> int
(a function that takes anint
and returns anint
).
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
OCaml version: The OCaml toplevel, version 5.3.0
Coq-LSP version: 0.2.3
Loading personal and system profiles took 1091ms.
PS C:\Users\User> ocaml C:\AI2025\ad2.ml
The curried result is: 7
PS C:\Users\User>
C. The Power of Currying: Partial Application
The real benefit of currying is partial application. This means you can supply some of the arguments to a curried function and get a new, specialized function back.
Let's extend our curried add
example.
(* Define the same curried 'add' function as before. *)
(* Type: int -> int -> int *)
let add x y =
x + y;;
(* --- Partial Application in Action --- *)
(* We apply 'add' with only *one* argument: the number 5. *)
(* This doesn't produce an error. Instead, it returns a new function. *)
(* This new function is "waiting" for the final argument, 'y'. *)
(* We bind this new function to the name 'add_five'. *)
let add_five = add 5;;
(* The inferred type of 'add_five' is: int -> int *)
(* It's a function that takes one integer and adds 5 to it. *)
(* Now we can use our new, specialized function 'add_five'. *)
(* Call 'add_five' with the argument 10. *)
let result1 = add_five 10;; (* This is equivalent to `add 5 10` *)
(* Call 'add_five' with the argument 3. *)
let result2 = add_five 3;; (* This is equivalent to `add 5 3` *)
(* Print the results. *)
Printf.printf "Adding 5 to 10 gives: %d\n" result1;;
(* Expected output: Adding 5 to 10 gives: 15 *)
Printf.printf "Adding 5 to 3 gives: %d\n" result2;;
(* Expected output: Adding 5 to 3 gives: 8 *)
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
OCaml version: The OCaml toplevel, version 5.3.0
Coq-LSP version: 0.2.3
Loading personal and system profiles took 1082ms.
PS C:\Users\User> ocaml C:\AI2025\par_ap.ml
Adding 5 to 10 gives: 15
Adding 5 to 3 gives: 8
PS C:\Users\User>
3. CONCLUSION
Davie, A. (1992). Introduction to Functional Programming Systems Using Haskell. Cambridge, England: Cambridge University Press.
Lipovača, M. (2011). Learn You a Haskell for Great Good!: A Beginner's Guide. San Francisco, CA: No Starch Press, Inc.
Thompson, S. (2011). The Craft of Functional Programming. Edinburgh Gate, Harlow, England: Pearson Education Limited.