如何在解释模式下运行haskell文件

如何在解释模式下运行haskell文件

本文介绍了如何在解释模式下运行haskell文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被告知可以解释haskell文件(我认为这意味着它们将像Ruby / Python / Perl一样工作)。尽管如此,在ghc上找不到命令行选项。它总是想编译我的文件。看看ghci也是如此,但它总是将我转化为repl。

I've been told you can interpret haskell files (which I assume means they will work like Ruby/Python/Perl). Can't find the command line option on ghc to do this, though. It always wants to compile my file. Took a look at ghci as well, but it always dumps me into a repl.

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

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.

推荐答案

$ runhaskell MyFile.hs

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

Alternatively, runghc (they're the same thing). 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中的独立单元,而不是每次运行整个事物,但显然对于较短的脚本来说,它是最简单和最简单的,只是运行整个事情。

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.

这篇关于如何在解释模式下运行haskell文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 15:55