# Submodule structs as "default" generic names

**URL:** <https://discourse.julialang.org/t/submodule-structs-as-default-generic-names/2931>\
**Category:** General Usage\
**Created:** [March 28, 2017, 3:29pm UTC](https://discourse.julialang.org/t/submodule-structs-as-default-generic-names/2931 "2017-03-28T15:29:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon94023334](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Post date:** [March 28, 2017, 3:29pm UTC](https://discourse.julialang.org/t/submodule-structs-as-default-generic-names/2931/1 "2017-03-28T15:29:13Z")

</div>

Here’s my current dilemma: I have a package/module `M` and within that, a submodule `SA` which exports structs `AFoo` and `ABar`. I would like, by default, the words `M.Foo` and `M.Bar` to refer to those two structs but I’d like other submodules (e.g., `SB`, which will export `BFoo` and `BBar`) to be able to override that default when `SB` is explicitly imported.

What’s the best way of doing this so that users don’t see warnings?

---

<div class="post-metadata">

**Author:** ![m-j-w](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/m-j-w/32/4541_2.png) [@m-j-w](https://discourse.julialang.org/u/m-j-w)\
**Post date:** [March 28, 2017, 9:07pm UTC](https://discourse.julialang.org/t/submodule-structs-as-default-generic-names/2931/2 "2017-03-28T21:07:07Z")

</div>

You may assing a datatype to any global variable in the module, and as long as this global is not marked const, you can reassign it either with `eval(M, expr)` in that module, or with a setter function. On Julia 0.6, this is how i would start, (note the optional submodule does not export but rather actively override)

```nohighlight
julia> workspace()
       module M

         setfoobar(foo, bar) = ( global Foo; global Bar; (Foo, Bar) = (foo, bar))

         module SA
           export AFoo, ABar # not actually required for this to work
           struct AFoo end
           struct ABar end
         end

         Foo = SA.AFoo # Default
         Bar = SA.ABar

       end

       M.Foo |> println
       M.Bar |> println

       # Consider this being imported on request

       module SB
         struct BFoo end
         struct BBar end
         using M.setfoobar
         __init__ () = setfoobar(BFoo, BBar)
       end

       M.Foo |> println
       M.Bar |> println
       
M.SA.AFoo
M.SA.ABar
SB.BFoo
SB.BBar

```

Certainly, having non-const globals has some disadvantages.  
I’m not convinced this is the best way of doing this, but it meets your specification.
