I am new to Erlang. If i do it
H = fun(X) -> X*X.
Then it’s wonderful. But if I moved this function to a module, it will say "Illegal expression". For example, this
H = misc_functions:square.
Please, help.
Erlang function references require the fun and arity keywords. Suppose square accepts one parameter, the correct assignment:
fun
square
H = fun misc_function:square/1
You can also do something like this:
1> F = fun(X) -> misc_function:square(X) end. #Fun<erl_eval.6.13229925> 2> F(4). 16 3>
Defining a function that calls inside your desired function.