Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

haskell - 如何在解释模式下运行Haskell文件(How to run a Haskell file in interpreted mode)

I've been told you can interpret Haskell files (which I assume means they will work like Ruby/Python/Perl).

(有人告诉我您可以解释Haskell文件(我认为这意味着它们将像Ruby / Python / Perl一样工作)。)

I can't find the command line option on GHC to do this, though.

(不过,我找不到GHC上的命令行选项。)

It always wants to compile my file.

(它总是想编译我的文件。)

Took a look at GHCi as well, but it always dumps me into a repl.

(也看了GHCi,但它总是使我陷入混乱。)

I'm basically wanting to just do ghc -i MyFile.hs (where -i is a made up flag that I'm pretending correllates to interpreted mode) and have it execute so that I can get quick feedback while I'm trying out ideas and learning.

(我基本上只是想做ghc -i MyFile.hs (其中-i是我假装与解释模式相关的虚假标志)并执行它,以便在尝试时可以快速获得反馈想法和学习。)

  ask by Joshua Cheek translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
$ runhaskell MyFile.hs

Alternatively, runghc (they're the same thing).

(或者,运行runghc (它们是同一回事)。)

ghci MyFile.hs will also start an interactive REPL session with MyFile.hs loaded, but if you want to run a main program then runhaskell is the way to go.

(ghci MyFile.hs也将启动一个交互式会话REPL MyFile.hs加载,但如果你想运行主程序,然后runhaskell是要走的路。)

It's probably a good idea to get into the habit of testing parts of your program as isolated units in GHCi rather than running the whole thing each time, but obviously for shorter scripts it's simplest and easiest just to run the entire thing.

(养成在GHCi中将程序的各个部分作为隔离单元进行测试的习惯,而不是每次都运行整个程序,这可能是一个好主意,但是显然,对于较短的脚本,仅运行整个程序是最简单,最容易的。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...