You can either do
struct Model
kernel::Kernel
end
or
struct Model{T <: Kernel}
kernel::T
end
In the first one, Model
does not have information in its type about which kernel it stores. This will probably lead to a performance penalty for you, but that can’t be said for sure without knowing the context.
The second one is a parametric type, parameterized by which kernel type it stores. Note that I made the type immutable. I expect that’s probably what you want also, as I don’t expect there is value in a mutable kernel (I could be wrong), and mutability also often comes with a performance penalty.
Although it was not part of the question:
struct ExponentialKernel <: Kernel
ExponentialKernel(rate::Number, x::Number) = exp(-1*rate*x)
end
I don’t think what you wrote does what you want:
julia> ExponentialKernel(5, 5)
1.3887943864964021e-11