2

What is the meaning of these statements in Haskell:

a)
(\x -> x + 1)

b)
 (\x -> x - 2)

c)
(\x -> mod (x * 3) 5)

I understand the x + 1, mod(x * 3) 5 etc but the \x before those statements makes them difficult for me to understand.

thanks for your help

Don Stewart
  • 136,266
  • 35
  • 360
  • 464
Kap
  • 633
  • 2
  • 6
  • 10
  • See also http://stackoverflow.com/questions/5587157/question-about-the-two-haskell-symbols-and-what-they-do-and – Don Stewart May 09 '11 at 01:37

1 Answers1

6

\ and -> define a lambda (you could call it an inline function or a nameless function). So \x->x is the same as \ x -> x is the same as a function which returns its argument. And \x y -> x + y is a function which returns the sum of its two arguments.

luqui
  • 58,573
  • 9
  • 138
  • 197
lijie
  • 4,691
  • 21
  • 25