# What are my options for code generation during compile time?

**URL:** <https://forums.fsharp.org/t/what-are-my-options-for-code-generation-during-compile-time/1199>\
**Category:** General\
**Tags:** beginners\
**Created:** [February 11, 2020, 1:03pm UTC](https://forums.fsharp.org/t/what-are-my-options-for-code-generation-during-compile-time/1199 "2020-02-11T13:03:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SerefArikan](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@SerefArikan](https://forums.fsharp.org/u/SerefArikan)\
**Post date:** [February 11, 2020, 1:03pm UTC](https://forums.fsharp.org/t/what-are-my-options-for-code-generation-during-compile-time/1199/1 "2020-02-11T13:03:08Z")

</div>

Greetings,  
I’ve been trying to map out my options for compile time metaprogramming and so far I could not find a supported way of plugging into the compilation with no limitations on the code that is generated.

As far as I can see, type providers allow me to supply types based on very simple input, such as a string, pointing at a schema etc and I wouldn’t be able to generate all constructs of the language such as generic types.

Options for code generation all seem to focus on parallel use of the f# compiler, as in, invoke compiler services, read some metadata from sources, then generate code, but I cannot see a well defined step in the compiling process to plug this behaviour in; similar to what compile time annotation processing supported by Java. I’d have to write a tool and write that in parallel to my code base, which is clunky.

The only project that seems to mention what I have in mind is this one: [GitHub - pezipink/MixinProvider: Type provider for generating and injecting F# code from compile time metaprograms](https://github.com/pezipink/MixinProvider)

Its definition pretty much sums up what I’m describing:

> The Mixin Provider is essentially a very powerful code generator - it evaluates an F# metaprogram at compile time, and compiles the resulting program to an assembly - or it can inject code into existing F# source files within your projects by using a combination of special dummy injection functions and a metaprogram.

but it is subject to same limitation that I seem to have come across: no point in the compiler’s various phases to invoke a mechanism to do code generation.

Am I missing an approach I could explore? I’d appreciate your confirmation about this indeed being the state of things. Very keen to hear alternatives that I may be missing.

All the best  
Seref

---

<div class="post-metadata">

**Author:** ![Nelkins](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/nelkins/32/173_2.png) [@Nelkins](https://forums.fsharp.org/u/Nelkins)\
**Post date:** [February 14, 2020, 5:14pm UTC](https://forums.fsharp.org/t/what-are-my-options-for-code-generation-during-compile-time/1199/2 "2020-02-14T17:14:50Z")

</div>

Possibly of interest:

> **[Applied Meta-Programming](https://7sharp9.dev/2019/04/24/2019-04-24-applied-metaprogramming-with-myriad/)**
>
> With Myriad And Falanx

> **[Myriad Intro](https://7sharp9.dev/2019/11/06/2019-11-06-myriad-intro/)**
>
> New Meta Programming Club Video - An Introduction to Myriad

---

<div class="post-metadata">

**Author:** ![SerefArikan](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@SerefArikan](https://forums.fsharp.org/u/SerefArikan)\
**Post date:** [February 14, 2020, 6:32pm UTC](https://forums.fsharp.org/t/what-are-my-options-for-code-generation-during-compile-time/1199/3 "2020-02-14T18:32:32Z")

</div>

Thank you. I found the link to this by accident while browsing F# weekly posts 🙂 My #1 pending material to read a.t.m.
