在Windows中将Haskell(.hs)编译为exe

Sud*_*ha 16 windows compiler-construction haskell

是否可以将一组.hs haskell文件编译到windows中的exe中?.hs- >.exe

Don*_*art 28

绝对.安装Haskell平台,它为您提供GHC,一个最先进的Haskell编译器.

默认情况下,它编译为可执行文件,并且在Linux或Windows上的工作方式相同.例如

给定一个文件:

$ cat A.hs
main = print "hello, world"
Run Code Online (Sandbox Code Playgroud)

用GHC编译:

$ ghc --make A.hs
[1 of 1] Compiling Main             ( A.hs, A.o )
Linking A.exe ...
Run Code Online (Sandbox Code Playgroud)

你现在可以运行:

$ ./A.exe
"hello, world"
Run Code Online (Sandbox Code Playgroud)

注意,这是在Cygwin下.但对于本机Windows也是如此:

C:\temp>ghc --make A.hs
[1 of 1] Compiling Main             ( A.hs, A.o )
Linking A.exe ...

C:\temp>A.exe
"hello, world"
Run Code Online (Sandbox Code Playgroud)


Kir*_* G. 5

对于从未编译过任何东西的人来说,知道Don Stewart的例子中的"C:\ temp>"指向.hs应该是的文件夹也可能是有用的.例如,如果您的用户帐户下有一个文件夹,请在其中包含您的hello.hs文件的"C:\ Users\Username\Haskell \",您可以通过键入cmd打开命令提示符,当它打开时,您将请参阅"C:\ Users\Username>".要编译您的文件,请键入以下内容:

ghc Haskell\hello.hs
Run Code Online (Sandbox Code Playgroud)

所以整行看起来应该是这样的:

C:\Users\Username>ghc Haskell\hello.hs
Run Code Online (Sandbox Code Playgroud)

如果您没有任何错误类型,您应该能够在与hello.hs文件相同的文件夹中看到结果.