开发者

How do I implement an F# Read Eval Print Loop (REPL)?

I would like to add an F# REPL to my application for live debugging purposes. I am looking at the source code for fsi.exe (F# Interactive) and there is a ton of stuff going on that looks like it pokes around with F# compiler internals. I cannot 开发者_JS百科get this same code to compile in the context of our application because of this.

Is there a nice simple example of implementing an F# REPL somewhere? I would have hoped for this to be fairly easy.


The short answer is that F# (unfortunatelly) doesn't currently provide any API for hosting F# Interactive in your applications. There are a lot of people asking for this - see for example this SO question.

There are essentially two things you could do about that:

  • You can modify the open-source release and compile fsi.exe as some DLL library that would provide the API you need. This isn't simple task - F# Interactive is tightly bound with the compiler (it compiles code you enter on the fly), but it should be doable to encapsulate the types implementing REPL into some type you could call (But you cannot just take some file out of it - you need to compile entire F# to get this working).

  • You can run fsi.exe as a separate process as Visual Studio does and send commands to it using standard input/output. You can get some more flexibility by loading your library when fsi.exe starts. The library could use .NET Remoting to connect back to your application and expose some data.

Unfortunatelly, these two options are probably the only things you can do at the moment.

EDIT I was thinking that I already answered this question somewhere (perhaps in email), but couldn't
find it! Thanks to Mauricio who found the exact duplicate (even with my duplicate answer... Doh!)


I've written a series of blog posts about using the open source F# interactive executable inside and WPF application.

The code base is available on github - https://github.com/oriches/Simple.Wpf.FSharp.Repl

The series of blog posts are:

http://awkwardcoder.blogspot.co.uk/2013/12/simple-f-repl-in-wpf-part-1.html

http://awkwardcoder.blogspot.co.uk/2013/12/simple-f-repl-in-wpf-part-2.html

http://awkwardcoder.blogspot.co.uk/2013/12/simple-f-repl-in-wpf-part-3.html

The final post is to follow soon.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜