Pablo Duque
Pablo Duque

Reputation: 383

Using struct from a module inside another module in Julia

I have found similar questions on SO but none of them seem to give an answer that works for my case.

I have a few modules, in one of them I create a mutable struct which I want to be able to use in the others. All files are at the same level:

In file_module_A.jl:

module A
   mutable struct MyType
      variable
   end
end

In file_module_B.jl:

module B
    # I need to import MyType here
end

In file_module_C.jl:

module C
    # I need to import MyType here
end

I have tried the followings without success:

Any ideas? Thanks in advance!

Upvotes: 0

Views: 1473

Answers (1)

fredrikekre
fredrikekre

Reputation: 10984

You need to use using ..A. using .A means to look for A in the current module (B in the example below), and you need an extra . to step up one module level, to Main if you run the example in the REPL:

module A
    mutable struct MyType
        variable
    end
end

module B
    using ..A: MyType
end

Upvotes: 3

Related Questions