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
  • 137,316
  • 36
  • 365
  • 468
Kap
  • 673
  • 2
  • 7
  • 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
  • 59,485
  • 12
  • 145
  • 204
lijie
  • 4,811
  • 22
  • 26