I hope this is an easy question, but I'm stuck. I want to define this
function
function u(consump,labor)
consump.^(1-sigmac)/(1-sigmac) + psi*(1-labor).^(1-sigmal)/(1-sigmal)
end
but I don't want to have to pass the parameters explicitly. They are never
going to change after the function is defined, so I would like it if I
could build them directly into the function as constants.
The problem is that I plan to stick this function into a type, like so
immutable UtilityFunction
u::Function
sigmac::Float64
sigmal::Float64
psi::Float64
end
I am unaware of any method in which u::Function could self-reference the
elements of its type, which would be convenient, but I feel like I should
be able to define u::Function with the parameters built in. I admit I don't
really understand the scoping rules for functions which are contained in a
type. Were I defining u as an external function, I think it would have
access to the variables in the global scope, so I could just define
constants there and this would be fine. Since I'm trying to stick it in a
type, I don't know.
As an aside, I plan to optionally use this function with the FastAnonymous
package. In that case it looks like this shouldn't be an issue, since
according to its documentation, "The value of any parameters gets "frozen
in" at the time of construction." That's exactly what I'm looking for here.
I am pretty sure this could be done with a macro in the type's constructor,
but I'm hoping there's a simpler option.