在Windows中编译Haskell程序:是否可以不下载Cygwin之类的东西? [英] Compiling Haskell programs in Windows: is it possible without downloading something such as Cygwin?
问题描述
我正在阅读向您学习Haskell,以获取极大的好处",并且已经达到了有关I/O操作的章节.我正在使用Windows,并且已经下载了GHCi和WinGHCi.
I am reading "Learn you a Haskell for great good", and have reached the chapter on I/O actions. I am using Windows, and have downloaded GHCi and WinGHCi.
我正在尝试编译一个简单的程序,并已在emacs上将文件另存为helloworld.hs
,其中包含main = putStrLn "hello, world"
.
I'm trying to compile a simple program and have saved a file on emacs as helloworld.hs
with main = putStrLn "hello, world"
in it.
这本书说
打开终端,导航到
helloworld.hs
所在的目录,然后输入以下内容:
Open your terminal, navigate to the directory where
helloworld.hs
is located, and enter the following:
$ ghc --make helloworld
但是,如果我在GHCi和WinGHCi上输入$ ghc --make helloworld
,则会收到诸如以下错误消息,可能是因为我需要在其他位置输入$ ghc --make helloworld
:
However, if I enter $ ghc --make helloworld
onto GHCi and WinGHCi I receive errors such as the one below, perhaps because I need to enter $ ghc --make helloworld
elsewhere:
<interactive>:7:1: error:
parse error on input ‘$’
Perhaps you intended to use TemplateHaskell
实际上,在该书的在线版本中(此处: http://learnyouahaskell.com/输入和输出),作者指出:
In fact, in the online edition of the book (here: http://learnyouahaskell.com/input-and-output), the author remarks that:
在本章中,我将假设您使用的是unix-y环境来学习Haskell.如果您使用的是Windows,建议您下载Cygwin,这是适用于Windows的类似于Linux的环境,也称为A.K.A.正是您所需要的.
For the purposes of this chapter, I'm going to assume you're using a unix-y environment for learning Haskell. If you're in Windows, I'd suggest you download Cygwin, which is a Linux-like environment for Windows, A.K.A. just what you need.
问题1 :为了能够通过输入$ ghc --make helloworld
来编译程序,我是否需要下载Cygwin或其他类似的东西?
Question 1: Is it necessary for me to download Cygwin, or some other such thing, in order to be able to compile the program by entering $ ghc --make helloworld
?
我问这个问题,因为如果还有其他编译程序的方法,那将非常有用,因为我在大学计算机上,未经许可就无法下载Cygwin之类的内容. (即使获得许可,也可能无法实现,具体取决于Cygwin的要求)
I ask this, since if there were some other way of compiling the program it would be very useful to know, since I am on a university computer and cannot download things like Cygwin without permission. (and even with permission it might not be possible, depending on what Cygwin requires)
问题2 :鉴于只有我大学的技术人员可以参加复活节活动,并且只有他们可以在此计算机上下载内容,我才能继续本章在I/O动作中?是否可以继续,而忽略涉及编译程序的部分?
Question 2: Given that only the technicians of my university are away for Easter, and only they can download things on this computer, how can I proceed with the chapter in I/O actions? Is it possible just to continue, but ignore the sections involving compiling programs?
推荐答案
在许多Unix和Linux外壳程序中(至少在我最熟悉的Bash中),默认提示符为$
.这就是外壳显示的内容.
In many Unix and Linux shells (at least in Bash with which I'm most familiar) the default prompt is $
. That's what the shell displays.
在Windows上,当您打开命令提示符时,通常会看到类似以下的内容:
On Windows, when you open a Command Prompt, you'll typically see something like this instead:
C:\Users\mark>
(这是我的提示.)
尽管说明中通常包含$
提示符,以指示代码是您希望在命令提示符下输入的内容,但您不应键入$
.只需键入ghc --make helloworld
并按 Enter .
While instructions often include the $
prompt in order to indicate that the code is something that you're expected to enter at a command prompt, you're not expected to type the $
. Just type ghc --make helloworld
and hit Enter.
此外,您不希望从GHCi内部执行此操作,而应从命令行执行. ghc
是命令行可执行文件(.exe
),例如git
.但是,它必须位于您的path
中,否则,每次运行该可执行文件时,您都必须键入完整路径.
Also, you're not expected to do this from within GHCi, but from the command line. ghc
is a command-line executable (an .exe
), just like e.g. git
. It has to be in your path
, though, or otherwise, you'll have to type the full path the executable every time you want to run it.
这篇关于在Windows中编译Haskell程序:是否可以不下载Cygwin之类的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!