Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Haskell (.hs) in windows to a exe

Is it possible to compile a set of .hs haskell files into a exe in windows? .hs -> .exe

like image 404
Sudantha Avatar asked Jun 10 '11 12:06

Sudantha


People also ask

How do I run a .HS file?

Open a command window and navigate to the directory where you want to keep your Haskell source files. Run Haskell by typing ghci or ghci MyFile. hs. (The "i" in "GHCi" stands for "interactive", as opposed to compiling and producing an executable file.)

How do I run a Haskell file on Windows?

If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt. Alternatively, if you are on Windows, you may choose WinGHCi in the Start menu. And you are presented with a prompt. The Haskell system now attentively awaits your input.


2 Answers

Absolutely. Install the Haskell Platform, which gives you GHC, a state-of-the-art compiler for Haskell.

By default it compiles to executables, and it works the same on Linux or Windows. E.g.

Given a file:

$ cat A.hs
main = print "hello, world"

Compile it with GHC:

$ ghc --make A.hs
[1 of 1] Compiling Main             ( A.hs, A.o )
Linking A.exe ...

Which you can now run:

$ ./A.exe
"hello, world"

Note, this was under Cygwin. But the same holds for native 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"
like image 58
Don Stewart Avatar answered Oct 01 '22 12:10

Don Stewart


For people who never compiled anything at all, it also might be useful to know that "C:\temp>" in the example by Don Stewart points to the folder in which .hs should be. For example, if you have a folder under your user account, say "C:\Users\Username\Haskell\" in which you have your hello.hs file, you open command prompt by typing cmd, when it opens, you'll see "C:\Users\Username>". To compile you file type the following:

ghc Haskell\hello.hs

So the entire line should look like:

C:\Users\Username>ghc Haskell\hello.hs

Provided you have no any mistypes, you should be able to see the result in the same folder as you have your hello.hs file.

like image 38
Kirill G. Avatar answered Oct 01 '22 10:10

Kirill G.