softshipper
softshipper

Reputation: 34099

What is the difference between ((+) 4) and \x -> (+) 4 x?

I am trying to understand CAF from the page https://wiki.haskell.org/Constant_applicative_form and confuse about the difference between ((+) 4) and \x -> (+) 4 x?

Why is the first a CAF and the later not? As a beginner, I can not see the difference.

Upvotes: 3

Views: 84

Answers (1)

Karol Samborski
Karol Samborski

Reputation: 2955

One way to read this is that:

  • ((+) 4) is an expression that produces the function: \x -> (+) 4 x

  • \x -> (+) 4 x is that function already.

And functions are not CAFs (we don't apply anything there).

Upvotes: 3

Related Questions