I essentially want to do the following:
typealias CVODE_BDF CVODE_BDF{:Newton,:Dense}
that is, allow a user to pass to my function CVODE_BDF
and, if they did not set any of the type parameters, interpret it as CVODE_BDF{:Newton,:Dense}
. I know that the typealias
doesn't actually work, but is there a way to simulate this? Like in the function, read T.parameters[1]
and somehow see that it was empty?
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
variadic keyword parameters cannot have default values.
The default parameter is a way to set default values for function parameters a value is no passed in (ie. it is undefined ). In a function, Ii a parameter is not provided, then its value becomes undefined . In this case, the default value that we specify is applied by the compiler.
All the parameters of a function can be default parameters.
You can do this if the function accepts objects of that type, rather than the type itself. E.g.
type MyObject{T}
end
const DefaultMyObject = MyObject{Int64}()
f{T}(x::MyObject{T}=DefaultMyObject) = T
f(), f(MyObj{Float64}())
gives
(Int64,Float64)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With