简体   繁体   English

用Mono解释F#文件

[英]Interpreting F# files with Mono

After installing F# on OS X with Homebrew, In Haskell (with GHC), it's possible run code on an interpreter. 在带有Homebrew的OS X上安装F#之后,在Haskell(带有GHC)中,可以在解释器上运行代码。 I was wondering if there is a way to run files without compiling them first in F#? 我想知道是否有一种方法可以运行文件而无需先在F#中对其进行编译? Maybe with fsharpi? 也许和fsharpi在一起?

Just to clarify, I do not mean the REPL itself, but running an app without intermediary files. 只是为了澄清,我不是指REPL本身,而是指运行没有中间文件的应用程序。

You can use fsharpi which is an interactive mode for F#. 您可以使用fsharpi ,它是F#的交互模式。 You can just start fsharpi and then type F# code in the console that starts: 您可以只启动fsharpi ,然后在启动的控制台中键入F#代码:

> 1 + 1;;
val it : int = 2

You can also write your code in a fsx file and pass it to fsharpi to have it executed. 您也可以将代码编写到fsx文件中,然后将其传递给fsharpi使其执行。 Say you have demo.fsx with: 假设您有demo.fsx其中包含:

printfn "Hello world"

You can then run fsharpi demo.fsx and it should print hello world for you! 然后,您可以运行fsharpi demo.fsx ,它将为您打印hello world!

Some people use F# from command line in this way, but it gets more productive if you setup your favorite editor to use F# - then you can type code directly in the editor and send it to F# Interactive using some command. 某些人以这种方式从命令行使用F#,但是如果您将自己喜欢的编辑器设置为使用F#,则会提高工作效率-然后您可以直接在编辑器中键入代码,然后使用某些命令将其发送给F#Interactive。 There are good plugins for Atom , Emacs, vim, Sublime and others - see the links here . 有一些适用于Atom ,Emacs,vim,Sublime和其他应用程序的插件- 请参见此处的链接

PS: It is worth adding that F# Interactive does not actually interpret the code. PS:值得补充的是,F#Interactive实际上并不解释代码。 It compiles it on the fly and runs it, so it has the same performance profile as compiling the code in the usual way. 它可以即时编译并运行它,因此它具有与以通常方式编译代码相同的性能配置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM