I can only point you to Microsoft.VisualBasic.VBCodeProvider and Microsoft.CSharp.CSharpCodeProvider which come in very handy for what you're trying to do and are the respective tools for Visual Basic and C# but there seems to be no such provider for F# at the moment.

Daniel

By on 9/1/2008 9:39 AM ()

I can only point you to Microsoft.VisualBasic.VBCodeProvider and Microsoft.CSharp.CSharpCodeProvider which come in very handy for what you're trying to do and are the respective tools for Visual Basic and C# but there seems to be no such provider for F# at the moment.

Daniel

Check Microsoft.FSharp.Compiler.CodeDom

By on 9/1/2008 11:34 AM ()

Good spot yashez!

Though this is not ideal for the application I was considering it's certainly more elegant than running fsc.exe. It's also good to know that efforts are being made to support many of the core interfaces of .NET languages.

I guess I could take in a string, wrap it in a module, attempt to add the [<ReflectedDefinition>] attribute to the top level definitions, compile, the load the assembly and instantiate the module in my appdomain. However a string -> Expr would save these error-prone steps. It would certainly be nice to have a definitive answer that a string -> Expr is not in the current CTP.

Having a context to compile an expression into would also be very useful. I take it that this is the magic of Fsi. Having programmatic access to this functionality would be powerful indeed.

I'd welcome any more comments on dynamic compilation and execution.

regards,

Danny

By on 9/1/2008 2:14 PM ()

I just spotted this article which you may find interesting:

Run-time code generation using System.Reflection.Emit (31st August 2008)

"The .NET platform represents a radical departure from the previous generation of native-code compiled languages. Whereas languages such as C++ and Fortran have distinct compilation and execution phases, the .NET platform deliberately blurs this distinction with run-time compilation of a distributable platform-independent Common Intermediate Language (CIL). This article examines the use of run-time code generation from F# using the System.Reflection.Emit namespace to implement a compiler for a simple bytecode language..."

[link:www.ffconsultancy.com]

I don't know what it talks about exactly though and it may well be that it's not about using F# syntax as input code. (still, it's interesting imo ;))

You need a subscription to the F# Journal to be able to read it.

Daniel

By on 9/10/2008 2:56 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper