module AB
using Reexport
include("A.jl")
include("B.jl")
@reexport using .A
@reexport using .B
end
And, both A, B has functions close!. Then, using close! causes warning like this: WARNING: both A and B export "close!"; uses of it in module AB must be qualified
(Of course, both A.close! and B.close! accept different types of arguments).
Yes, this is impossible. It has been requested elsewhere (under the limitation you mention that the two functions take strictly different arguments) but I don’t know if it’s on anyone’s roadmap to do this (maybe by 2.0).
What you should do is have AB define close!, and then A and B add methods to it
# in AB
# no methods, just defining the name
function close! end
export close!
They will be methods under the close! function. The multiple dispatch design of Julia means that you can have methods acting on different tuples of argument types under the same function name. In this case the recommended way is to declare the function in module AB, and add methods to it from module A and module B.
Yes, exactly. It is the same idea as when you implement an object that should have length(obj), you do
Base.length(x::MyType) = # ...
to extend the function length from Base to your own type. In your case, the AB package creates an interface that A and B extend for their own specific cases, which is a common design pattern.