I am in the process of making a library to convert F# to C++.
Here is an example:
[<ReflectedDefinition>] module Functions = //must declare delegate with same name as let bound function type Add = delegate of int * int -> int let Add(a,b) = a + b open Functions module Host = let main() = //get function pointer to exported C++ function let m = FunctionPointer<Add> Assert.AreEqual(m.Invoke(1,2),Add(1,2))
As you can see it is quite straight forward to use.
So how does this work?
F# allows you to read the definition of a function / member at runtime so in the above example it reads an AST of the form "let Add(a,b) = a + b".
Within the FunctionPointer definition that AST is transformed into a C++ AST and then outputs the code into a template project, runs MSBuild, copies the dll to the program folder, dynamically loads the dll and gets the exported function.
I can then call this function directly from F#.
I am not finished.
Why am I doing this?
1. It is fun.
2. Maybe it will be useful.
Does anyone here think this is useful?
If so what would you use it for?
What functionality would make it more useful for you?
Thank you for your time.
Edited by RivieraKid, 22 February 2014 - 06:09 AM.