Haskell 你好世界,Eclipse IDE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1220638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Haskell Hello world, eclipse IDE
提问by Scott Weinstein
I'm having trouble getting "hello world" going with eclipseFP and Haskell.
我在使用 eclipseFP 和 Haskell 时遇到了“hello world”问题。
I have the following code,
我有以下代码,
module Main where
main = putStr "Hello world!"
and when I compile it with
当我编译它时
ghc.exe .\H1.hs -o hw.exe
it works fine, but under eclipseFP, when I run it I only see the following in the console window:
它工作正常,但在 eclipseFP 下,当我运行它时,我只能在控制台窗口中看到以下内容:
GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Ok, modules loaded: Main.
Prelude Main>
What mistakes am I making?
我犯了什么错误?
采纳答案by rtperson
From what little I've seen of EclipseFP, it's merely an interface for GHCi. Which means, as far as I'm concerned, that there's no reason to use it, since you get all the bad of Eclipse (the bloat, the bottomless thirst for memory, the tortoise-on-sedatives speed), with absolutely none of the good (the indexing, the debugger, the management of your tool stack).
从我对 EclipseFP 的了解来看,它只是 GHCi 的一个接口。这意味着,就我而言,没有理由使用它,因为你会遇到 Eclipse 的所有坏处(膨胀、对记忆的无底洞、乌龟镇静剂的速度),绝对没有优点(索引、调试器、工具堆栈的管理)。
So what noob mistake did you make? You used Eclipse. It's OK -- an easy mistake to make. If you were learning Scala, Eclipse might have been the way to go. But with Haskell, you're better off running GHCi from the command line and using an editor like Notepad++ (which has decent syntax highlighting). For once, the command-line/editor combination is preferable not because it's macho, but because it's more useful.
那么你犯了什么菜鸟错误?您使用了 Eclipse。没关系 - 一个容易犯的错误。如果您正在学习 Scala,Eclipse 可能是您的最佳选择。但是使用 Haskell,您最好从命令行运行 GHCi 并使用 Notepad++ 之类的编辑器(具有不错的语法突出显示)。这一次,命令行/编辑器组合更可取,不是因为它有男子气概,而是因为它更有用。
If you absolutely must have an IDE, the pickings are few right now, but here's what I've found.
如果您绝对必须有一个 IDE,那么现在选择很少,但这是我发现的。
And of course, any found in the answer to this question.
I haven't used it, but Leksah seems to be the most feature-rich IDE to date. Personally, I'm sticking with Notepad++ and the command line.
我没用过,但 Leksah 似乎是迄今为止功能最丰富的 IDE。就个人而言,我坚持使用 Notepad++ 和命令行。
回答by Tom Lokhorst
I haven't used EclipseFP in years, so bear that in mind.
我已经很多年没有使用过 EclipseFP,所以请记住这一点。
What appears to be happening is that EclipseFP is loading GHCi in the console.
GHCi is an interactive Haskell shell, in which you can evaluate simple expressions. It also apparently loaded your module Main
, so you can use GHCi to call functions in your module.
似乎正在发生的事情是 EclipseFP 正在控制台中加载 GHCi。GHCi 是一个交互式 Haskell shell,您可以在其中计算简单的表达式。它显然还加载了您的模块Main
,因此您可以使用 GHCi 调用模块中的函数。
If you type in :main
in the console, it will run you program and print "Hello world!", you could also call other functions you define in your program or standard Haskell functions.
如果您在:main
控制台中输入,它会运行您的程序并打印“Hello world!”,您还可以调用您在程序中定义的其他函数或标准 Haskell 函数。
However, what you may want to do is set EclipseFP to execute your program when you run, and I can't remember how to do that, probably somewhere in the "Run" menu.
但是,您可能想要做的是将 EclipseFP 设置为在您运行时执行您的程序,我不记得该怎么做,可能在“运行”菜单中的某处。
回答by Peter
In the project explorer click on your project and then click the right mouse button and select Run As > Run Configurations > Run As Haskell Application
.
在项目资源管理器中单击您的项目,然后单击鼠标右键并选择Run As > Run Configurations > Run As Haskell Application
.
回答by L Hand
In the eclipse run menu, select run configurations. Under the Automation tab enter main in the command to run on launch and it will do what you expect.
在eclipse运行菜单中,选择运行配置。在自动化选项卡下,在命令中输入 main 以在启动时运行,它将按照您的预期运行。
回答by hiena
Never used eclipse but what you see is ghci, GHCi is GHC's interactive environment. Your module was loaded successfully in ghci, you can type main in ghci to run the function main of your program, actually you can call any function of your program that way.
eclipse没用过但是看到的是ghci,GHCi是GHC的交互环境。你的模块在 ghci 中加载成功,你可以在 ghci 中输入 main 来运行你程序的 main 函数,实际上你可以通过这种方式调用你程序的任何函数。