[Haskell-cafe] identity function

Edward Amsden eca7215 at cs.rit.edu
Mon Dec 20 23:36:46 CET 2010

It does precisely what you'd think. It returns the value passed in.
It's mainly used in cases where a higher-order function expects a
function, but you don't want to modify anything. See for instance

If I want to extract a value from a Maybe, but I don't particularly
care to apply a function to it, I can write (for instance)

maybe 0 id ma

Where 'ma' is my maybe value. (There's a library function fromMaybe,
but this should illustrate the idea.)

On Mon, Dec 20, 2010 at 5:14 PM, A Smith <asmith9983 at gmail.com> wrote:
> 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.
> --
> Andrew
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

Edward Amsden
Computer Science
Rochester Institute of Technology

More information about the Haskell-Cafe mailing list