[Haskell-cafe] identity function
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...
More information about the Haskell-Cafe