This method cannot be implemented since numbers are immutable.

On Thu, Jun 23, 2016 at 1:20 PM, Davide Lasagna <lasagnadav...@gmail.com>
wrote:

> I have a function that operates on an AbstractVector object `fs`, defined
> like this:
>
> function foo{T}(fs::AbstractVector{T})
>     out = zero(T)
>     for f in fs
>         # do some with out and f, e.g. sum
>     end
>     scale!(out, 42)
> end
>
> This code should be generic, and the eltype `T` could be a number, e.g., a
> Float64, or a vector, e.g. Vector{Float64}. The function loops over the
> entries of `fs` and then scales the `out` variable by a magic number 42.
>
> The above definition works well when `T` is a vector, but fails when `T`
> is a scalar with a MethodError, as scale! does not have a method when both
> inputs are numbers. A possible method definition would be something along
> the lines of
>
> scale!(a::Number, b::Number) = a*b
>
> Probably `scale!` is not the right way to implement this. Any suggestions
> that apply to 0.4 and/or 0.5 are very welcome!
>
> Thanks
>
>

Reply via email to