# Code Generation

**URL:** <https://discourse.julialang.org/t/code-generation/22985>\
**Category:** General Usage\
**Created:** [April 10, 2019, 3:19am UTC](https://discourse.julialang.org/t/code-generation/22985 "2019-04-10T03:19:31Z")\
**Posts on this page:** 3\
**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:** [April 10, 2019, 3:19am UTC](https://discourse.julialang.org/t/code-generation/22985/1 "2019-04-10T03:19:32Z")

</div>

I have a question which I am having trouble figuring out.

assume I have the following function  
gentype() = PP

assume I have a type as QQ{MM{gentype(){LL{Int}},Z}, NN{LL{Z}}} I want to transform it to another type  
XQQ{XMM{PP{LL{Int}},XZ}, XNN{XLL{XZ}}} via generating the following code:

transformtype((transformtype(QQ)){transformtype((transformtype(MM)){transformtype((transformtype((transformtype(gentype))())){transformtype((transformtype(LL)){transformtype(Int)})}), transformtype(Z)}), transformtype((transformtype(NN)){transformtype((transformtype(LL)){transformtype(Z)})})})

As you see here,  
PP{LL{Int}} hasn’t changed because the type is PP. The others types are transformed to their new versions. So my question is how can I do this at runtime. How does transformtype look like? What is its signature ? I assume I will need some sort of a state.

Or is there a better way to get this done?

Thanks

---

<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:** [April 10, 2019, 3:28am UTC](https://discourse.julialang.org/t/code-generation/22985/2 "2019-04-10T03:28:29Z")

</div>

```nohighlight
transformtype((transformtype(QQ, state)){transformtype((transformtype(MM, state)){transformtype((transformtype((transformtype(gentype, state))(), state)){transformtype((transformtype(LL, state)){transformtype(Int, state)}, state)}, state), transformtype(Z, state)}, state), transformtype((transformtype(NN, state)){transformtype((transformtype(LL, state)){transformtype(Z, state)}, state)}, state)}, state))

```

where state includes transformed and untransformed versions of the types, so that the outer one selects and chains and updates the state. This should work.  
Thanks

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 10, 2019, 6:07am UTC](https://discourse.julialang.org/t/code-generation/22985/3 "2019-04-10T06:07:56Z")

</div>

Please quote your code and make an MWE.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …
