# Using everything exported in a module and its submodules

**URL:** <https://discourse.julialang.org/t/using-everything-exported-in-a-module-and-its-submodules/117024>\
**Category:** New to Julia\
**Tags:** classes, modules, parameters, using\
**Created:** [July 14, 2024, 8:09am UTC](https://discourse.julialang.org/t/using-everything-exported-in-a-module-and-its-submodules/117024 "2024-07-14T08:09:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)\
**Post date:** [July 14, 2024, 8:09am UTC](https://discourse.julialang.org/t/using-everything-exported-in-a-module-and-its-submodules/117024/1 "2024-07-14T08:09:07Z")

</div>

I am [currently replacing some String arguments of my mutable structure with dedicated types instead.](https://github.com/jkhamphousone/RingStarProblems.jl/issues/5)

The following MWE works perfectly fine:

```julia
module MyPackage
  ### Some code
  module Options
  
      module SolveMod
          struct Both end # public interface
          struct BranchBendersCut end # public interface
          ## Some other options...
          const USolveMod = Union{Both,BranchBendersCut} # not part of the public interface
  
          export USolveMod
      end
  
      module SPSolve
          struct Poly end # public interface
          struct LP end # public interface
          const USPSolve = Union{Poly,LP} # not part of the public interface
          export USPSolve
      end
  
      export SolveMod, SPSolve
  end
  
  
  using .Options: SolveMod.USolveMod, SPSolve.USPSolve
  using Parameters
  @with_kw mutable struct OptimizeParameters @deftype String
     solve_mod::USolveMod
     sp_solve::USPSolve
  end
end

```

In my non MWE-case, I have 7 (out of 32) parameters for my solver that need a dedicated type, instead of two in the MWE (SolveMod and SPSolve). So I was wondering if I could write something like:

`using .Options: All` Instead of `using .Options: SolveMod.USolveMod, SPSolve.USPSolve 3rdClass.Uniontype, 4thClass.Uniontype (etc.)`

😃

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [July 14, 2024, 8:25am UTC](https://discourse.julialang.org/t/using-everything-exported-in-a-module-and-its-submodules/117024/2 "2024-07-14T08:25:14Z")

</div>

You could export all of them in options, and a user could `import .Options` in case they don’t want all of them.

(In principle one could even export via a for loop, but doing it explicitly might be clearer.)

---

<div class="post-metadata">

**Author:** ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)\
**Post date:** [July 14, 2024, 8:29am UTC](https://discourse.julialang.org/t/using-everything-exported-in-a-module-and-its-submodules/117024/3 "2024-07-14T08:29:34Z")

</div>

Thank you for your reply 😃 Am I not already exporting all of them?

cf. line:

```julia
export SolveMod, SPSolve, WriteResults # etc. other types

```

I am not sure I understand what you suggest 😅 I have modified my MWE, because I forgot to mention that module `Options` is within module `MyPackage`.

Also, I tried to use:  
`import .Options`  
instead of  
`using .Options: SolveMod.USolveMod, SPSolve.USPSolve` as suggested in your reply but then `USolveMod` becomes undefined.

`ERROR: LoadError: UndefVarError: `USolveMod` not defined`

Anyway, I just remarked that it is not so a big deal to write all the 7 modules by hand 😆

---

<div class="post-metadata">

**Author:** ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)\
**Post date:** [July 14, 2024, 9:49am UTC](https://discourse.julialang.org/t/using-everything-exported-in-a-module-and-its-submodules/117024/4 "2024-07-14T09:49:50Z")

</div>

Okay! I found it all 😃 I indeed had to export **everything**

```julia
module MyPackage
  module Options
  
      module SolveMod
          struct Both end # public interface
          struct BranchBendersCut end # public interface
          struct ILP end # public interface
          struct NoOptimize end # public interface
          struct gF end # public interface
          struct gFexploreonlyILP end # public interface
          struct gFexploreonlyben end # public interface
          const USolveMod = Union{Both,BranchBendersCut,ILP,NoOptimize,gF,gFexploreonlyILP,gFexploreonlyben} # not part of the public interface
  
          export Both, BranchBendersCut, ILP, NoOptimize, gF, gFexploreonlyILP, gFexploreonlyben, USolveMod
      end
  
      using .SolveMod
  
      module SPSolve
          struct Poly end # public interface
          struct LP end # public interface
          const USPSolve = Union{Poly,LP} # not part of the public interface
          export Poly, LP, USPSolve
      end
  
      using .SPSolve
  
      module WResults
          struct WHTML end # public interface
          struct WLocal end # public interface
          const UWriteResults = Union{WHTML,WLocal,Bool} # not part of the public interface
          export WHTML, WLocal, UWriteResults
      end
      using .WResults
  
      export SolveMod, SPSolve, WResults, Both, BranchBendersCut, ILP, NoOptimize, gF, gFexploreonlyILP, gFexploreonlyben, USolveMod, Poly, LP, USPSolve, WHTML, WLocal, UWriteResults
  end
end

using .Options

```

Now it works like a charm, thanks 🙂

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [July 14, 2024, 10:28am UTC](https://discourse.julialang.org/t/using-everything-exported-in-a-module-and-its-submodules/117024/5 "2024-07-14T10:28:12Z")

</div>

It looks like this could be a usecase for the [Reexport](https://github.com/simonster/Reexport.jl) package.
