# Using a type in a generated module

**URL:** <https://discourse.julialang.org/t/using-a-type-in-a-generated-module/11306>\
**Category:** General Usage\
**Created:** [May 31, 2018, 8:14pm UTC](https://discourse.julialang.org/t/using-a-type-in-a-generated-module/11306 "2018-05-31T20:14:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [May 31, 2018, 8:14pm UTC](https://discourse.julialang.org/t/using-a-type-in-a-generated-module/11306/1 "2018-05-31T20:14:14Z")

</div>

Hi,

I am looking for a way to generate a module using a type which is not imported in the generated module, meaning i need the full path to the type.

How can i get this done?  
Here is an example:

```nohighlight
module DF

	is_module(a) = false

	is_module(e::Expr) = e.head == :module

	make_top_level(e::Expr) =
           if e.head == :block && any( is_module.(e.args) )
               Expr(:toplevel, e.args...)
           elseif e.head == :block
               Expr(:block, make_top_level.(e.args)...)
           else
               e
           end
    end

	struct MM
		x::Int
	end

	macro cm(amod,typ)
		esc(make_top_level(quote
			module $amod
				export mms
				struct mms
					x::$typ
				end
			end
		end))
	end

	@cm ESS MM
end

```

the generated code is as follows:

```nohighlight
:($(Expr(:toplevel, :( # REPL[5], line 3:), :(module ESS # REPL[5], line 3: # REPL[5], line 4:
    export mms # REPL[5], line 5:
    struct mms # REPL[5], line 6:
        x::MM
    end
    end))))

```

However i want it to be like

```nohighlight
:($(Expr(:toplevel, :( # REPL[5], line 3:), :(module ESS # REPL[5], line 3: # REPL[5], line 4:
    export mms # REPL[5], line 5:
    struct mms # REPL[5], line 6:
        x::DF.MM
    end
    end))))

```

Thanks

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [June 1, 2018, 12:33am UTC](https://discourse.julialang.org/t/using-a-type-in-a-generated-module/11306/3 "2018-06-01T00:33:35Z")

</div>

You could try

```nohighlight
macro cm(amod,typ)
	esc(make_top_level(quote
		module $amod
			export mms
			struct mms
				x::$(current_module()).$typ
			end
		end
	end))
end

```

with `x::$(current_module()).$typ`
