[Haskell-cafe] identity function

Sean Leather leather at cs.uu.nl
Tue Dec 21 08:23:04 CET 2010

> I've been reviewing the library, and have come unstuck with the *id*function.
> What's its purpose and can someone give me an example of its practical use.

It's purpose is simply to be the identity function. The type says exactly
what it does.

Prelude> :t id
id :: a -> a

It's often useful in combination with higher-order functions.

Prelude> :t foldr (.) id
foldr (.) id :: [a -> a] -> a -> a

Here's a slightly complicated way to add a list of numbers:

Prelude> foldr (.) id (map (+) [1..5]) 0

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101221/d16df5cb/attachment-0001.htm>

More information about the Haskell-Cafe mailing list