Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a F# script in the context of C# Application

Is it easily possible to run a F# script from within (and in the context) of a C# Application (host).

With 'in the context' I mean the following should be true:

  • no separate process for the execution of the script
  • access from the F# script to the static content of host application (classes, properties, methods)

Basically I'm am looking for an API similar to this hypothetical API call

FSharpScriptRunner.RunInContext(string script);

Please help.

-Matthias

like image 979
mklein Avatar asked Jul 28 '11 13:07

mklein


People also ask

HOW IS F value calculated?

The F value is used in analysis of variance (ANOVA). It is calculated by dividing two mean squares. This calculation determines the ratio of explained variance to unexplained variance. The F distribution is a theoretical distribution.

How do I run an F-test in Excel?

To perform F-Test, go to the Data menu tab, and from the Data Analysis option, select F-Test Two-Sample Of Variances. Select both the data population in the variable 1 and 2 range, keeping alpha as 0.05 (Standard for 95% probability). This will give us a final F-Test Calculation.


2 Answers

There is currently no such api, but you can pretty easily do something similar in a couple of steps:-

1) Use the F# CodeDom, (FSharp.Compiler.CodeDom.dll) available in the powerpack, to dynamically compile your script. The power pack contains apis to compile a single file and to allow you to add references to your current application, thus give the script access to the classes, properties, and methods of the host application.

2) At the end of the compilation stage you should have a dynamic assembly in memory. You can then use reflection to create a dynamic instance of an object from your script and execute it.

like image 100
Robert Avatar answered Nov 13 '22 12:11

Robert


Why don't you just compile the F# code into an assembly then reference that from your C# app?

like image 44
Andrew Hare Avatar answered Nov 13 '22 12:11

Andrew Hare