Question

How would I include the fsi REPL in my application for scripting?

The F# PowerPack doesn't appear to have anything for that.

Was it helpful?

Solution

OTHER TIPS

One way would be learning the sources of FSI available from few repositories mentioned in the comments to the question and then somehow exposing its functionality to your application by modifying the sources (changing visibility, etc). This way apparently is steep and painful.

Fortunately, some work in this direction has been already done along the lines of FSharp.Compiler.Service, so another way may be embedding FSI into your application as a standardized service. Few details upon embedding FSI as a service are available in the following presentation given by Don Syme and Tomas Petricek during NYC 2013 SkillMatters days.

The presentation provides a link to (experimental) implementation of FSI service within Microsoft.FSharp.Compiler.Interactive.Shell namespace, so the embedding may be as easy as in the snippet below:

open Microsoft.FSharp.Compiler.Interactive.Shell
.....
let fsi = FsiEvaluationSession([| "fsi.exe"; "--noninteractive"|], inStream, outStream, errStream)
.....
match fsi.EvalExpression(codeLines) with
    | Some value -> value.ReflectionValue
    | None -> raise (System.ArgumentException("fsi cannot evaluate expression"))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top