简体   繁体   English

Ghc无法正常启动[Windows 7 64位]

[英]Ghc not starting properly [Windows 7 64 bit]

I've just installed Haskell Platform, and ghci works fine, but for some reason i can't launch ghc. 我刚刚安装了Haskell平台,ghci可以正常工作,但是由于某些原因我无法启动ghc。 It crashes approximately 0,5 seconds after i start it. 我启动它约0.5秒后便会崩溃。

In the haskell platform directory, i've got the following "ghc-related" .exe's: ghc ghc.pkg runghc 在haskell平台目录中,我具有以下“与ghc相关的” .exe文件:ghc ghc.pkg runghc

runghc.exe "works", but the only thing that happens is that a blank, black terminal appears. runghc.exe可以运行,但是唯一发生的是出现空白的黑色终端。

Help! 救命!

Guessing from your comments, I'd say you don't quite understand what GHC is and what GHCi is. 从您的评论中猜测,我会说您不太了解GHC和GHCi是什么。 GHC is the Glasgow Haskell Compiler. GHC是格拉斯哥Haskell编译器。 All it does is compile your Haskell code into an executable. 它所做的只是将您的Haskell代码编译为可执行文件。 GHCi is the interactive GHC, it lets you type in code and have it compiled line-by-line. GHCi是交互式GHC,它使您可以键入代码并逐行进行编译。 You can launch GHCi by running ghci from your command line, but when you run ghc , you have to pass it more arguments to have it do anything. 您可以通过从命令行运行ghci来启动GHCi,但是当您运行ghc ,您必须传递更多的参数才能使其执行任何操作。

For example, if I had the file HelloWorld.hs in the folder C:\\projects\\haskell , with HelloWorld.hs having the contents 例如,如果我在文件夹C:\\projects\\haskell有文件HelloWorld.hs ,其中HelloWorld.hs包含内容

module Main where

sayHello :: String -> String
sayHello name = "Hello, " ++ name ++ "!"

main :: IO ()
main = do
    putStrLn "What is your name?"
    name <- getLine
    putStrLn $ sayHello name

I could open a command line (the > indicates the prompt, it isn't part of the commands) and run 我可以打开命令行( >表示提示,它不是命令的一部分)并运行

> cd C:\projects\haskell
> ghc --make HelloWorld.hs -o hello.exe
> hello.exe
What is your name?
bheklilr
Hello, bheklilr!

I could also do something like 我也可以做类似的事情

> cd C:\projects\haskell
> ghci
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :load HelloWorld.hs
Ok, modules loaded: Main
*Main>

From which point I can do things like 从这一点上我可以做类似的事情

*Main> sayHello "World"
"Hello, World!"
*Main> sayHello $ sayHello "World"
"Hello, Hello, World!!"
*Main> :main
What is your name?
bheklilr
Hello, bheklilr!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM