I know that something like \x->x+1 is an anonymous function definition that gets an x and adds one to it. But I saw the expression return x = (\ r -> x) when I was reading an article here.
What does (\ r -> x) mean? Why after backslash is empty?
There is no difference: \ r -> x or \r -> x have the same meaning, much as 1+1 and 1 + 1 have the same meaning. Whitespace after \ is irrelevant.
So, return x is just \r -> x, which is a function which takes a parameter r, ignores it, and yields x.
Moreover, since r gets ignored, we tend to write \ _ -> x (or const x - which is defined as const x _ = x) instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With