Julia 不同模块中相同类型之间没有签名匹配
我的程序中有以下(简化的)模块结构 我还详细介绍了每个模块的简化结构Julia 不同模块中相同类型之间没有签名匹配,julia,Julia,我的程序中有以下(简化的)模块结构 我还详细介绍了每个模块的简化结构 module Entities export Agent, Space struct Agent . end struct Space . end end 现在,当我运行scheduler.jl文件时,出现以下错误 LoadError: MethodError: no method matching synthetise_schedule(::Arra
module Entities
export Agent, Space
struct Agent
.
end
struct Space
.
end
end
现在,当我运行scheduler.jl
文件时,出现以下错误
LoadError: MethodError: no method matching synthetise_schedule(::Array{Main.Scheduler.Loader.Entities.Agent,1}, ::Array{Main.Scheduler.Loader.Entities.Space,1})
它看起来像REPL将Main.Scheduler.Loader.Entities.*
和Main.Scheduler.Entities.*
视为不同的类型,尽管它们最终都引用相同的原始类型Entities.
现在,我不确定这种行为是因为我在每个模块中缺少一组指令,还是因为它是Julia中的预期行为。
在任何情况下,我如何确保我的synthetise\u schedule
函数接受Main.Scheduler.Loader.Entities.*
类型作为输入?您使用在代码中包含(“./Entities.jl”)
两次。请注意,include
类似于文件内容的复制粘贴。所以本质上你在不同的模块中定义了两次相同的东西。虽然定义是相同的(它是代码的术语),但它们是分开的(请将其视为在两个不同的名称空间中复制粘贴相同的代码两次)
您应该只包含(“./entities.jl”)
一次,然后在代码的其他两部分中引用您创建此include
的命名空间
module Scheduler
include("./loader.jl")
include("./entities.jl")
using .Loader: load_data, read_config
using .Entities: Agent, Space
function main()
spaces, agents = load_data(read_config("scenarios/eq_2.json"))
synthetise_schedule(agents, spaces, order)
# println(typeof(spaces), "\t", typeof(agents), "\t", typeof(locations), "\t", typeof(order))
end
function synthetise_schedule(agents::Vector{Agent}, spaces::Vector{Space})
.
end
main()
end
LoadError: MethodError: no method matching synthetise_schedule(::Array{Main.Scheduler.Loader.Entities.Agent,1}, ::Array{Main.Scheduler.Loader.Entities.Space,1})