September 8, 2026

Haskell for Hobos -- Lambda Functions

These sound exotic, but are really no big deal.

What they are is an anonymous function with a curious notation. A typical example would be that you want to run map (or filter). Suppose we want to run map on a list and apply the function 2*x*x +13*x +5 to each element. Here is how we could do it using a lambda function

newlist = map ( \x -> 2*x*x + 13*x + 5 ) list
The backslash kicks off the lambda function (it looks somwhat like the greek letter "lambda"). The argument follows, then the arrow operator, followed by the body of the function.

Often you can use a section or partially applied function instead of a lambda, but if you want to use a lambda, go right ahead and do so.

Perhaps you need two arguments (maybe you need a function for zip).

newlist = zip ( \x y -> x * 2y ) list1 list2


Have any comments? Questions? Drop me a line!

Tom's software pages / tom@mmto.org