Erlang equivalents of Haskell where/partial/lambda
I am no expert in erlang but I will try to answer.
Nesting functions
out(A) ->
X = A + 1,
SQ = fun(C) -> C*C end,
io:format("~p",[SQ(X)]).
here SQ function has access to parent variables.
In Lambda
This is same as above, you can use fun
to define your anonymous functions.
Partial application
I don't think erlang has partial function application in any sane way. The only thing you can do is to wrap functions to return function.
add(X) ->
Add2 = fun(Y) -> X + Y end,
Add2.
Now you can do something like
1> c(test).
{ok,test}
2> A=test:add(1).
#Fun<test.0.41627352>
3> A(2).
3
Erlang doesn't have nested functions in the sense that Haskell and other languages do. When @Satvik created a function using SQ = fun(C) -> C*C end
he was creating a closure, or fun in Erlang, and not a nested function. The syntax fun (...) -> ... end
creates a fun or closure. which is not really the same thing.
Partial evaluation as in Haskell does not exist in Erlang, though you can hack it using funs.
You define in-line lambdas (funs) with the fun
syntax. So you map becomes:
lists:map(fun (X) -> X+X end, [1,2,3])