2013-12-09 40 views
4

我如何将fsi REPL包含在我的脚本应用程序中?F#交互式应用程序是否为开源代码?

F# PowerPack似乎没有任何东西。

+2

是的,这是。它的来源是在GitHub上:https://github.com/fsharp/fsharp/tree/master/src/fsharp/fsi –

+0

不知道为什么这会被搁置,我还会问这个问题? – AwkwardCoder

+2

Ramon给出的链接的另一种替代方法是[FSharp.Compiler.Service](https://github.com/fsharp/FSharp.Compiler.Service),该方法公开了类似于您的场景中所需的额外功能。 –

回答

4

一个办法是学习FSI的来源可以从问题的评论中提到的几个存储库中获得,然后以某种方式将其功能暴露给您的应用程序通过修改来源(改变能见度等)。这种方式显然是陡峭而痛苦的。

幸运的是,这方面的一些工作已经按照FSharp.Compiler.Service的方法完成了,所以另一种方式可能是将FSI作为标准化服务嵌入到您的应用程序中。以下presentation由Don Syme和Tomas Petricek在NYC 2013 SkillMatters日期间提供了有关嵌入FSI作为服务的详细信息。

呈现提供了一个链接Microsoft.FSharp.Compiler.Interactive.Shell命名空间内(实验)实施FSI服务,这样的嵌入可以是如在下面的代码段一样简单:

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")) 
+0

此代码尚未将其添加到FSharp.Compiler.Service(AFAIK),但它在我的本地分支中可用:https://github.com/tpetricek/fsharp/tree/fs-extend。请参阅InteractiveService示例:https://github.com/tpetricek/fsharp/tree/fs-extend/samples/InteractiveService –

相关问题