0

I want to make my Application configuration as F# file wich will be compiled to dll. (like XMonad configuration with xmonad.hs on haskell). I found it more interesting and just better way then using XML serialization.

So is there any way how can I compile single file (or more) to Library with some configuration like

module RNExcel.Repository

open RNExcel.Model

    type ExpenseReportRepository() =
        member x.GetAll() =
            seq{ yield {Name="User1" 
                        Role="someRole" 
                        Password = "123321"
                        ExpenseLineItems = 
                            [{ExpenseType="Item1" 
                              ExpenseAmount="50"};
                             {ExpenseType="Item2" 
                              ExpenseAmount="50"}]}
                 yield {Name="User2"
                        Role="Estimator" 
                        Password = "123123"
                        ExpenseLineItems = 
                            [{ExpenseType="Item1" 
                              ExpenseAmount="50"};
                             {ExpenseType="Item2" 
                              ExpenseAmount="125"}]}    }

my idea was to run shell .... and msbuild the project , but I don't think it will works for every user with .net 4

cnd
  • 32,616
  • 62
  • 183
  • 313

2 Answers2

1

Check out the F# Power Pack, specifically the FSharp.CodeDom library. You can use this library to compile F# code at run-time and, with a little Reflection thrown in, can likely achieve your goal of code-as-configuration with minimal fuss.

Ben
  • 6,023
  • 1
  • 25
  • 40
  • Are you sure? I was under the impression the F# CodeDOM was incomplete and could not be used to compile F# code at run-time. – J D Dec 21 '10 at 09:16
  • Having never tried this particular library, I can't honestly say - judging by the Codeplex front page, at least some of the functionality is in place; I'd guess that the most rudimentary features are there. Whether it's enough for @nCdy is anyone's guess... – Ben Dec 21 '10 at 09:53
1

I think that using CodeDOM provider from the PowerPack as Ben suggested is a way to go. I'd just like to add a few things (and it didn't fit into the comment box).

To parse and compile the F# code with the configuration, you need just to compile the source file that the users write using F# PowerPack. The compilation part of PowerPack is complete and works just fine. It invokes the F# compiler under the cover and gives you the compiled assembly back. The only problem is that the users of your application will need to have F# compiler installed (and not just the redist).

The incomplete part of F# CodeDOM provider is generating F# code from CodeDOM trees (because the trees were not designed to support F#), but that's not needed in this case.

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • My users got no F# compiler installed (and not just the redist). That's sad , I need something else then. – cnd Dec 22 '10 at 03:49
  • >The compilation part of PowerPack is complete and works just fine Are you sure? http://stackoverflow.com/questions/9565196/compileassemblyfromfile – RomanKovalev Mar 06 '12 at 08:31