I have the following code
using Plots
function test()::nothing
A::Array{Float64,1} = rand(Float64,100)
plot(A)
end
Which I run in julia like this
julia> include("main.jl")
test (generic function with 1 method)
julia> test()
ERROR: MethodError: First argument to `convert` must be a Type, got nothing
Stacktrace:
[1] test() at /path/to/main.jl:85
[2] top-level scope at REPL[2]:1
Why do I get the error First argument to convert must be a Type, got nothing ?
Well, this problem is related to the fact that you were using
nothingin annotation, but correct type isNothing(note capitalN).nothingis an object,Nothingis a type of this object.So you should use something like
Note, that I had to add
nothingas return value and explicitdisplayto show actual plot.But, to be honest, main problem is not the
Nothing, but overspecialization. Type annotations in functions do not speed up calculations, you should use them only when they are really needed, for example in multiple dispatch.Idiomatic code looks like this
Note, that I removed all extra annotations and unnecessary
Float64inrand, since it is default value.