I can't seem to import a function with typed arguments. Luckily, I have a minimal failing example.
Given a Query
defined in structs.jl
:
module Structs
export Query
struct Query
name::String
data::Int
end
end
And a simple function dist
which uses this type:
module Utils
include("structs.jl")
using .Structs: Query
export dist
function dist(x::Query, y::Query)
return (x.data - y.data) ^ 2
end
end
Why can dist
not be found, when I call it in import_test.jl
?
include("structs.jl")
using .Structs: Query
include("utils.jl")
using .Utils: dist
a = Query("a", 1)
b = Query("b", -1)
println(dist(a, b))
Instead, it fails with the error:
ERROR: LoadError: MethodError: no method matching dist(::Query, ::Query)
Stacktrace:
[1] top-level scope at none:0
[2] include at .\boot.jl:317 [inlined]
[3] include_relative(::Module, ::String) at .\loading.jl:1041
[4] include(::Module, ::String) at .\sysimg.jl:29
[5] exec_options(::Base.JLOptions) at .\client.jl:229
[6] _start() at .\client.jl:421
in expression starting at C:\Users\mr_bo\julia_test\import_test.jl:13
However, if I remove the types from the dist
function, such that it becomes function dist(x, y)
, the error no longer occurs.
Am I import the Query
type/struct incorrectly?