Answer the question
In order to leave comments, you need to log in
Explain about closures in FP?
Here, for example, is the Haskell code: add a b = a + b
Everything seems to be fine, the function is clean. But you can also write it in another way, with blackjack closure and lambdas: add = \a -> \b -> a + b
And here something becomes incomprehensible. It seems like both functions should be pure (after all, as far as I understand, in Haskell only functions of the IO () type or something like that can be "dirty", but here - the most ordinary functions). But at the same time, the lambda \b -> a + b
, in theory, should not see the variable a
. But she sees. Does that mean she's not clean?
Can you please explain how closures coexist with the functional paradigm?
Answer the question
In order to leave comments, you need to log in
Net. Consider foo = add 2
, foo x
for some x
always returns the same value, and also does not produce any externally observable effect, and therefore falls under the definition of a pure function. Those. foo = add 2
is identical to the function foo x = 2 + x
, which is obviously pure.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question