I have package called sandwich, it then has:
A file flavours.jl which defines a struct HamCheeseSandwich.
The file factory.jl is a module which first first runs include("flavours.jl") and has a method make_sandwich which creates a HamCheeseSandwich, except rather than producing a HamCheeseSandwich it returns sandwich.factory.HamCheeseSandwich
The last file is printer.jl , here the sandwich made in factory.jl fails with MethodError: no method matching print_sandwich(::sandwich.factory.HamCheeseSandwich)
# printer.jl
function print_sandwich(sandwich::HamCheeseSandwich)
println("Enjoy your sandwich")
println(sandwich)
end
When I check the types
Julia> sandwich.factory.HamCheeseSandwich == HamCheeseSandwich
false
Which suggests the problem is my use of include has created two versions of HamCheeseSandwich.
To reproduce
A working example can be seen at this repo:https://github.com/this-josh/Julia-structs-question
This behaviour can be reproduced with
using sandwich
s = factory.make_sandwich(true,false)
print_sandwich(s)
My question is how should I use includes within my package to prevent the duplication of HamCheeseSandwich and to make sure I can still type hint as in printer.jl