I don't think that the case
expression in your code causes the problem. Rather the function definition itself is malformed.
If I interpret your code correctly, you want to define a recursive function for multiplication. And fun(Y-1)
is intended as recursive function call?
But in your case Mult
is a variable which is assigned an anonymous function (or rather two nested anonymous functions) and I don't think that anonymous functions allow for recursion.
How about the following variation:
-module (mult).
-export ([mult/1]).
mult(X) ->
fun (Y) ->
case Y of
0 -> 0;
Y -> X + (mult(X))(Y-1)
end
end.
(to be put in a separate file).