简体   繁体   中英

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. It crashes approximately 0,5 seconds after i start it.

In the haskell platform directory, i've got the following "ghc-related" .exe's: ghc ghc.pkg runghc

runghc.exe "works", but the only thing that happens is that a blank, black terminal appears.

Help!

Guessing from your comments, I'd say you don't quite understand what GHC is and what GHCi is. GHC is the Glasgow Haskell Compiler. All it does is compile your Haskell code into an executable. GHCi is the interactive GHC, it lets you type in code and have it compiled line-by-line. 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.

For example, if I had the file HelloWorld.hs in the folder C:\\projects\\haskell , with HelloWorld.hs having the contents

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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